WPF DataGrid source updating on cell changed

后端 未结 4 1780
走了就别回头了
走了就别回头了 2020-12-28 15:24

I am new to the WPF ,and i use it to build a point of sale system.

I have a DataGrid control in the main window bound to an ObservableCollection

4条回答
  •  醉酒成梦
    2020-12-28 15:34

    The code in the accepted answer didn't work for me since the row fetched from ItemContainerGenerator.ContainerFromItem(item) results in null and the loop be quite slow.

    A more simple solution to the question is the code provided here: http://codefluff.blogspot.de/2010/05/commiting-bound-cell-changes.html

    private bool isManualEditCommit;
    private void HandleMainDataGridCellEditEnding(
      object sender, DataGridCellEditEndingEventArgs e) 
    {
     if (!isManualEditCommit) 
     {
      isManualEditCommit = true;
      DataGrid grid = (DataGrid)sender;
      grid.CommitEdit(DataGridEditingUnit.Row, true);
      isManualEditCommit = false;
     }
    }
    

提交回复
热议问题