Make Keys.Enter work like Keys.Tab does not work on TemplateAddRow
this is my code
/ / remove the KeyActionMappings for Keys.Enter
foreach (Infragistics.Win.UltraWinGrid.GridKeyActionMapping ogKam in Grid.KeyActionMappings) { if (ogKam.KeyCode == Keys.Enter) { Grid.KeyActionMappings.Remove(ogKam);
}
// then add new mapping for Keys.Enter so it's work like Keys.Tab
foreach (Infragistics.Win.UltraWinGrid.GridKeyActionMapping ogKam in Grid.KeyActionMappings) { if (ogKam.KeyCode == Keys.Tab) { newKam = new Infragistics.Win.UltraWinGrid.GridKeyActionMapping(Keys.Enter, ogKam.ActionCode, ogKam.StateDisallowed, ogKam.StateRequired, ogKam.SpecialKeysDisallowed, ogKam.SpecialKeysRequired); Grid.KeyActionMappings.Add(newKam); } }
Result :
Keys.Enter still not work on TemplateAddRow like Keys.Tab
After I press Enter it's move to the next new row. How to make it move to next cell on TemplateAddRow ?
Solution Please..
Thanks
Wowww..great
it's work.. thank you very much.
This code will not work properly.
bullfreak said:foreach (Infragistics.Win.UltraWinGrid.GridKeyActionMapping ogKam in Grid.KeyActionMappings) { if (ogKam.KeyCode == Keys.Enter) { Grid.KeyActionMappings.Remove(ogKam); } }
You should never use Remove or Add inside of a foreach for a collection because Remove will change the items in the collection and mess up the enumerator. The proper way to remove items from a collection like this is to loop through the collection backwards by index. Like so:
for (int i = Grid.KeyActionMappings.Count; i >=0; i--) { Infragistics.Win.UltraWinGrid.GridKeyActionMapping ogKam = Grid.KeyActionMappings[i]; if (ogKam.KeyCode == Keys.Enter) { Grid.KeyActionMappings.Remove(ogKam); } }