I have a grid where only a single column can be edited. Regardless of how cells in this column are entered (mouse, tab key, up arrow, down arrow), I want the text in the cell highlighted upon entry. Accessing the cell via the tab key does this but mouse, up arrow, down arrow do not. What is the best/easiest way to do this? Thanks.
The up and down arrows keys do not actually change the ActiveCell in the grid. At least not by default.
What happens when you press up/down in your application?
Do you have code that is calling PerformAction or handling the Key events of the grid to move the focus up and down?
I added this code to handle the up and down arrows keys and it worked for me:
private void ultraGrid1_KeyDown(object sender, KeyEventArgs e) { switch (e.KeyCode) { case Keys.Up: this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false, false); this.ultraGrid1.PerformAction(UltraGridAction.AboveCell, false, false); this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false, false); e.Handled = true; break; case Keys.Down: this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false, false); this.ultraGrid1.PerformAction(UltraGridAction.BelowCell, false, false); this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false, false); e.Handled = true; break; } }
Only problem is you have to make sure the cell is in edit mode or you'll get an exception.
What if you used the same code in the AfterCellActivate event?
this works if I navigate to the cell with the mouse, tab, return this works fine - however up/down arrow this tihs does not work.
private void ultraGrid1_AfterEnterEditMode(object sender, EventArgs e) { UltraGrid grid = (UltraGrid)sender; EmbeddableEditorBase editor = grid.ActiveCell.EditorResolved; if (editor.SupportsSelectableText) editor.SelectAll(); }