datagrid not advance to next cell after commit

Jul 14, 2011 at 8:42 PM

I wrote a custom cell editor for cell content editing. User clicks a button in the editor to commit the changes. The editor then artificially generates an Enter key down event to notify data grid to commit the change. The changes are committed, but it did not advance to the next cell - the cell that was just edited still has the default blue background. The worst thing is that when user clicks on the cell that was just edited to edit it again, data grid sends the content of the next cell to the editor.

The artificial Enter key down event is generated as:

     var key = Key.Enter;
     var target = this;
     var routedEvent = Keyboard.KeyDownEvent;
                  new KeyEventArgs(
                    key) { RoutedEvent = routedEvent }

It seems that the data grid is confused about the "current" cell after the edit. Does anyone know how to fix the issue? Thanks!