DataGrid ItemEndEdit Fired Twice

Sep 3, 2009 at 11:27 AM

Hello,

I have an ObservableCollection that is bound to a datagrid and registered the ItemEndEdit event to use for commit changes to the DB when user ends editting a row. I have followd the great article at http://www.codeproject.com/KB/WPF/WPFDataGridExamples.aspx and everything things to be fine except for the fact I'm getting the event fired twice every time I commit a change.

If I edit a single cell and hit enter, I get two messages, causing 2 database transactions, etc... I have not registered to any other event on the datagrid control. Please have a look on the stack Trace for the both events:

> OtimizeStandard.exe!OtimizeStandard.PieceUIObjects.pieces_ItemEndEdit(System.ComponentModel.IEditableObject sender = {OtimizeStandard.PieceUIObject}) Line 34 C#
  [External Code] 
  OtimizeStandard.exe!OtimizeStandard.PieceUIObjects.ItemEndEditHandler(System.ComponentModel.IEditableObject sender = {OtimizeStandard.PieceUIObject}) Line 65 + 0x11 bytes C#
  OtimizeStandard.exe!OtimizeStandard.PieceUIObject.EndEdit() Line 295 + 0x11 bytes C#
  [External Code] 
  WPFToolkit.dll!Microsoft.Windows.Controls.DataGrid.OnExecutedCommitEdit(System.Windows.Input.ExecutedRoutedEventArgs e = {System.Windows.Input.ExecutedRoutedEventArgs}) Line 2339 + 0xa bytes C#
  WPFToolkit.dll!Microsoft.Windows.Controls.DataGrid.OnExecutedCommitEdit(object sender = {Microsoft.Windows.Controls.DataGrid Items.Count:3}, System.Windows.Input.ExecutedRoutedEventArgs e = {System.Windows.Input.ExecutedRoutedEventArgs}) Line 2239 C#
  [External Code] 
  WPFToolkit.dll!Microsoft.Windows.Controls.DataGrid.EndEdit(System.Windows.Input.RoutedCommand command = {System.Windows.Input.RoutedCommand}, Microsoft.Windows.Controls.DataGridCell cellContainer = {Microsoft.Windows.Controls.DataGridCell: 1}, Microsoft.Windows.Controls.DataGridEditingUnit editingUnit = Row, bool exitEditMode = true) Line 3192 C#
  WPFToolkit.dll!Microsoft.Windows.Controls.DataGrid.CommitEdit(Microsoft.Windows.Controls.DataGridEditingUnit editingUnit = Row, bool exitEditingMode = true) Line 3161 + 0x30 bytes C#
  WPFToolkit.dll!Microsoft.Windows.Controls.DataGrid.CommitAnyEdit() Line 3169 + 0x10 bytes C#
  WPFToolkit.dll!Microsoft.Windows.Controls.DataGrid.OnEnterKeyDown(System.Windows.Input.KeyEventArgs e = {System.Windows.Input.KeyEventArgs}) Line 5462 + 0x9 bytes C#
  WPFToolkit.dll!Microsoft.Windows.Controls.DataGrid.OnKeyDown(System.Windows.Input.KeyEventArgs e = {System.Windows.Input.KeyEventArgs}) Line 5102 C#
  [External Code] 


> OtimizeStandard.exe!OtimizeStandard.PieceUIObjects.pieces_ItemEndEdit(System.ComponentModel.IEditableObject sender = {OtimizeStandard.PieceUIObject}) Line 34 C#
  [External Code] 
  OtimizeStandard.exe!OtimizeStandard.PieceUIObjects.ItemEndEditHandler(System.ComponentModel.IEditableObject sender = {OtimizeStandard.PieceUIObject}) Line 65 + 0x11 bytes C#
  OtimizeStandard.exe!OtimizeStandard.PieceUIObject.EndEdit() Line 295 + 0x11 bytes C#
  [External Code] 
  WPFToolkit.dll!Microsoft.Windows.Controls.DataGrid.CommitRowItem() Line 3418 + 0x14 bytes C#
  WPFToolkit.dll!Microsoft.Windows.Controls.DataGrid.OnExecutedCommitEdit(System.Windows.Input.ExecutedRoutedEventArgs e = {System.Windows.Input.ExecutedRoutedEventArgs}) Line 2350 C#
  WPFToolkit.dll!Microsoft.Windows.Controls.DataGrid.OnExecutedCommitEdit(object sender = {Microsoft.Windows.Controls.DataGrid Items.Count:3}, System.Windows.Input.ExecutedRoutedEventArgs e = {System.Windows.Input.ExecutedRoutedEventArgs}) Line 2239 C#
  [External Code] 
  WPFToolkit.dll!Microsoft.Windows.Controls.DataGrid.EndEdit(System.Windows.Input.RoutedCommand command = {System.Windows.Input.RoutedCommand}, Microsoft.Windows.Controls.DataGridCell cellContainer = {Microsoft.Windows.Controls.DataGridCell: 1}, Microsoft.Windows.Controls.DataGridEditingUnit editingUnit = Row, bool exitEditMode = true) Line 3192 C#
  WPFToolkit.dll!Microsoft.Windows.Controls.DataGrid.CommitEdit(Microsoft.Windows.Controls.DataGridEditingUnit editingUnit = Row, bool exitEditingMode = true) Line 3161 + 0x30 bytes C#
  WPFToolkit.dll!Microsoft.Windows.Controls.DataGrid.CommitAnyEdit() Line 3169 + 0x10 bytes C#
  WPFToolkit.dll!Microsoft.Windows.Controls.DataGrid.OnEnterKeyDown(System.Windows.Input.KeyEventArgs e = {System.Windows.Input.KeyEventArgs}) Line 5462 + 0x9 bytes C#
  WPFToolkit.dll!Microsoft.Windows.Controls.DataGrid.OnKeyDown(System.Windows.Input.KeyEventArgs e = {System.Windows.Input.KeyEventArgs}) Line 5102 C#
  [External Code] 

What do you think it migh be happening....

Thanks in Advance,

Igor.