I want to keep the focus in the AddRow when the user press Enter key in a Cell. When the user click on the TemplateRow the grid create an AddRow, if the user then begin editing in a AddRow and press Enter key the grid move to the TemplateAddRow and automatically create another AddRow, how to prevent this? I want to create an AddRow ONLY when the user clik on the TemplateAddRow. Thanks.
Hi,
The grid's keyboard behavior is controlled by the KeyActionMappings collection. So to disable the Return key for committing a row, you have to loop through the collection and remove any key actions for CommitRow.
In order to prevent the list for getting out of synch while looping through it and removing items, it's a good idea to loop through the list backwards.
Here's some sample code that shows you how:
for (int i = this.ultraGrid1.KeyActionMappings.Count - 1; i >= 0; i--) { GridKeyActionMapping keyActionMapping = (GridKeyActionMapping)this.ultraGrid1.KeyActionMappings[i]; if (keyActionMapping.ActionCode == UltraGridAction.CommitRow) this.ultraGrid1.KeyActionMappings.Remove(keyActionMapping); }
Fantastic, this resolved my problem. Thank you so much Mike, you are a genius!