Hi, i want to be able to delete the active row by pressing de delete key in the keyboard even if there is an active cell in the row (not in edit state). When you select the whole row by clicking on the row selector and then you press the delete key, the active row is deleted. But if you have an active cell and then you press the delete key nothing happens.
I've tried to add KeyActionMapping, but nothing again.
this.ultraGrid1.KeyActionMappings.Add(new GridKeyActionMapping( Keys.Delete, UltraGridAction.DeleteRows, UltraGridState.InEdit, UltraGridState.Cell | UltraGridState.Row, SpecialKeys.All, 0));
Do I have to handle the delete key in the keypress event?
Is there a keyboard way to deactivate the current cell, and let the row active?
Thnx.
I think the reason your new Mapping probably doesn't work is that there are already mappings in the collection that handle the delete key. Since you are adding yours to the bottom of the collection, the existing ones get processed first. Try Inserting your mapping to the top of the collection and see if that works.
I think that will work, but if not, you might want to try finding the existing mapping that handles the delete key and change it, rather than adding a new one. There are actually quite a few mappings that handle the delete key, but all but one of them has a StateDisallowed of Selected. So you can just search the collection for a mapping whose KeyCode is Delete and whose StateDisallowed is none.
Thanks for your answer. I've tried to set my mapping at position 0, but it doesn't work either.
I've listed all mappings and these are all the mappings for the delete key (reordered):
KeyCode;ActionCode;StateRequired;SpecialKeysRequired;StateDisallowed;SpecialKeysDisallowed
Delete;DeleteCells;CanDeleteCells;0;InEdit, SwapDroppedDown, FilterDroppedDown;AllDelete;DeleteRows;Row;0;InEdit;AllDelete;Cut;CanCut;Shift;InEdit, SwapDroppedDown, FilterDroppedDown;AltCtrlDelete;DeleteRows;Cell, Row;0;InEdit;All
and i've put an event handler in the keydown event to see what the grid state is, and when you have an active cell the state is : Cell, Row. When you select the entire row clicking on the selector the state is : Row.
Thanx.
Hi,
Okay, I see the problem. The DeleteRows action operates on the selected rows. So even with the proper KeyActionMapping, there are no selected rows and therefore nothing to delete.
One way to deal with this would be to add another mapping. The first one to select the active row and the select one to call DeleteRow. Both actions would otherwise have the same properties. I'm not sure there is an action to select the row, though.
The easiest way to do this would be to simply use the KeyDown event of the grid.
private void ultraGrid1_KeyDown(object sender, KeyEventArgs e) { UltraGrid grid = (UltraGrid)sender; if (e.KeyCode == Keys.Delete) { if (grid.Selected.Rows.Count == 0 && grid.ActiveRow != null && (grid.ActiveCell == null | grid.ActiveCell.IsInEditMode == false)) { grid.ActiveRow.Selected = true; grid.DeleteSelectedRows(); e.Handled = true; } } }