Hi!
I'm having an issue : i have a form with a grid on it. The grid can be edited, and the behaviour i need is the following : when editing a cell, if the Esc key is pressed i want the grid to commit the row and display a message.
At this moment the grid loses the newly entered data and return to the initial value when esc is pressed.
Here's how i've implemented (the isEditMode is a flag for when the grid is in edit mode, and HasModifiedValues is a flag that gets set to true on BeforeCellUpdate)
void ulgGrid_KeyUp(object sender, KeyEventArgs e) {
if (e.KeyCode == Keys.Escape) {
if (IsEditMode) {
ulgGrid.PerformAction(UltraGridAction.CommitRow);
if (HasModifiedValues) {
if (MessageBox.Show("You have some unsaved changes. Are you sure you want to roll them back?", "Warning!", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) {
CancelModifications();
}
if (IsEditMode && !HasModifiedValues) {
Thank you!
Hello ,
You could change the key action mapping for Escape from KayActionMapping of the UltraGrid. To do this you could use the following code:
foreach (GridKeyActionMapping key in ultraGrid1.KeyActionMappings)
{
if (key.KeyCode == Keys.Escape && key.ActionCode == UltraGridAction.UndoCell)
key.ActionCode = UltraGridAction.CommitRow;
If you use my suggestion there will no need to handle any key events of the Grid.
Let me know if you have any further questions.
You will probably want to make the same change for the UltraGridAction.UndoRow action, too.
It worked great!
Thank you Hristo and Mike!