If I add a new row to the grid through any means - by using the add button, or by using a template add row (top or bottom) I am unable to cancel adding the new row.
E.g. I click on the add row to begin editing the row, then I press the escape key because I no longer want to add the row. The row remains in the grid with any changes I have made, and when clicking off the row the IEditableObject.EndEdit is fired, whereas the new object edit should be cancelled when the escape key is pressed.
I've tried using the same binding source with the stock Microsoft DataGridView control and it behaves as expected - i.e. pressing the escape key will cancel adding the new row.
Is there a way that UltraGrid will support using the escape key to cancel adding new rows or do I have to manually intercept the escape key press and manipulate the calls to the bindingsource myself?
Thanks,
Reeve.
Hi Reeve,
Pressing Escape once only cancels the edit in the current cell. You need to press Escape a second time to cancel the entire row.
If you want to make it so that pressing escape once cancels the entire row, you could modify the grid's KeyActionMappings to do this, I think. You would just have to change the Action on the existing key mapping that cancels the cell and make it cancel the row instead.
Thanks for your reply.
Pressing the escape key multiple times doens't appear to have any effect on the grid Tracing into the events it appears that CancelNew is never called no matter how many times I press escape (from the ICancelAddNew interface), this means the row is never removed from the data source even if editing is cancelled.
The stock windows grid supports ICancelAddNew correctly so I suspect there is a way to get the UltraGrid to support this correctly.
I can't find anything helpful in the documentation about the KeyActionMappings, is there anywhere I should look for specific help on this topic?
If pressing Cancel twice is not working, then something is wrong. I just tested this out and it works fine for me. Perhaps your new row is not really an addnew row. Maybe something is comitting the row to the underlying data source and this it's just an edited row, not an addnew row. Have you tried just placing a new grid on a form to test this out or have you only tested it in your full application?
The KeyActionMappings should be documented in the help under the KeyActionMappings property. There's a complete list of the mappings there, I beleive.