0

I am trying to enable the user to add new row/data to a DataGrid that is twoway bound to an XML file. I can edit all values, but no matter what I have tried, the blank row at the end of the grid just won't show up.

I am trying to accomplish this mostly in XAML, with minimal code behind. I don't want the user to have to click a button to add the row either (Which I can accomplish).

Here is an example of my DataGrid. It updates my XML file with 0 code behind

<DataGrid  Name="masterCrewGrid" CanUserAddRows="True" CanUserDeleteRows="True" DataContext="{StaticResource CrewInfo}" ItemsSource="{Binding XPath=/Names/Name}" AutoGenerateColumns="False" CellEditEnding="masterCrewGrid_CellEditEnding" >
      <DataGrid.Columns>
            <DataGridTemplateColumn Header="Active">
                 <DataGridTemplateColumn.CellTemplate>
                       <DataTemplate>
                            <CheckBox IsChecked="{Binding XPath=@isActive, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                      </DataTemplate>
                 </DataGridTemplateColumn.CellTemplate>
             </DataGridTemplateColumn>
             <DataGridTextColumn Header="Family Name" Binding="{Binding XPath=Family, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
             <DataGridTextColumn Header="First Name" Binding="{Binding XPath=First, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
             <DataGridTextColumn Header="Middle Name" Binding="{Binding XPath=Middle, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
             <DataGridTextColumn Header="Birthday" Binding="{Binding XPath=Birthday, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
             <DataGridTextColumn Header="Crew Position" Binding="{Binding XPath=CrewPosition, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
      </DataGrid.Columns>
</DataGrid>

Can somebody please explain why new rows won't show up? Is it something to do with the grid being bound to an XML file?

Tronald
  • 1,520
  • 1
  • 13
  • 31

1 Answers1

0

I would guess that when you bind directly to the XML File it is readonly. Take a XMLDataProvider and bind to that. Then you can modify with RowEditEnding Event:

Take a look here for more info:

How do I create a new row in WPF DataGrid when it is bound to an XmlDataProvider?

Community
  • 1
  • 1
MarkusE
  • 545
  • 4
  • 20