WPF DataGrid bound data update process

Original: processing WPF DataGrid bound data up to date

By default, after datagrid bound data source, in a column after editing interface, the data will not be updated to memory object. If there is a command to get the currently selected row (memory objects) found that the data is not updated over on the same line.

Solution:

In the column's binding properties plus UpdateSourceTrigger, the following example XAML



   
   
  1. <DataGrid Name="dgProducts" IsReadOnly="False" CanUserAddRows="False" Grid.Row="1"
  2. CanUserDeleteRows= "False" AutoGenerateColumns= "False" Hyperlink.Click= "dgProducts_Click">
  3. <DataGrid.Columns>
  4. <DataGridTextColumn Header="产品编码" IsReadOnly="True" Binding="{Binding Path=ProductNO, Mode=TwoWay}"/>
  5. <DataGridTextColumn Header="产品名称" IsReadOnly="True" Width="150" Binding="{Binding Path=ProductName, Mode=TwoWay}"/>
  6. <DataGridTextColumn Header="规格型号" IsReadOnly="True" Width="150" Binding="{Binding Path=ProductSpec, Mode=TwoWay}"/>
  7. <DataGridTextColumn Header="生产数量" IsReadOnly="False" Binding="{Binding Path=MakeNums, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>
  8. <DataGridHyperlinkColumn Header="操作" Width="*" Binding="{Binding Path=PCmd}" />
  9. </DataGrid.Columns>
  10. </DataGrid>
When such real-time editing Datagrid cell data will immediately update the value of the data source.

UpdateSourceTrigger enumeration details see
http://msdn.microsoft.com/zh-cn/library/system.windows.data.updatesourcetrigger(v=vs.95).aspx


Guess you like

Origin www.cnblogs.com/lonelyxmas/p/12075396.html