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.
What if you used the same code in the AfterCellActivate event?
Only problem is you have to make sure the cell is in edit mode or you'll get an exception.
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; } }
I can't see any reason why this would flicker.There's no highlight applied to the ActiveCell by default. Maybe you have an ActiveCellAppearance applied to the grid?
Even if that were the case, the only reason you would see a flicker is if the grid was forced to paint in between the calls to set the ActiveCell and the call to PerformAction for EnterEditMode.
Mike,I have also implemented this solution in my application. However, I notice that every so often there is a flickering on the new cell just before it enters edit mode...presumably from its highlight when the UltraGridAction.BelowCell is called. Is there a quick and easy way to get rid of that flickering?Thanks
Yes - I wound up doing something very similar to your code - thanks...
cNavigation is e:keycode...
IF lEditing THEN curGrid:PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction:ExitEditMode, false, false). IF cNavigation = "up" OR (cNavigation = "tab" AND lShiftKey = TRUE) OR (cNavigation = "return" AND lShiftKey = TRUE) THEN curGrid:PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction:AboveRow, false, false). ELSE IF cNavigation = "down" OR (cNavigation = "tab" AND lShiftKey = FALSE) OR (cNavigation = "return" AND lShiftKey = FALSE) THEN curGrid:PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction:NextRow, false, false). ELSE IF cNavigation = "Next" THEN curGrid:PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction:PageDownRow, false, false). ELSE IF cNavigation = "PageUp" THEN curGrid:PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction:PageUpRow, false, false). IF lEditing THEN DO: curGrid:ActiveRow = curGrid:Rows:Item[curGrid:ActiveRow:Index]. curRow = curGrid:Rows:Item[curGrid:ActiveRow:Index]. curGrid:PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction:FirstCellInRow). curGrid:ActiveRow:Cells[cCell]:Activate(). curGrid:PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction:EnterEditMode, false, false). END.
Your code appears to be essentially the same as mine. The only reason I can see why this would not work is if you are using RowLayouts.
In that case, the BelowCell action won't work, because in a RowLayout situation, the grid can't neccessarily tell what cell is below or above the current cell - since a RowLayout can have overlapping cells.
In that case, you can do this:
private void ultraGrid1_KeyDown(object sender, KeyEventArgs e) { UltraGrid grid = (UltraGrid)sender; switch (e.KeyCode) { case Keys.Up: UltraGridRow prevRow = grid.ActiveCell.Row.GetSibling(SiblingRow.Previous); if (prevRow != null) { this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false, false); prevRow.Cells[grid.ActiveCell.Column].Activate(); this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false, false); e.Handled = true; } break; case Keys.Down: UltraGridRow nextRow = grid.ActiveCell.Row.GetSibling(SiblingRow.Next); if (nextRow != null) { this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false, false); nextRow.Cells[grid.ActiveCell.Column].Activate(); this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false, false); e.Handled = true; } break; } }
In the keydown event of the grid I have the following code...
METHOD PRIVATE VOID ultraGrid1_KeyDown( INPUT sender AS System.Object, INPUT e AS System.Windows.Forms.KeyEventArgs ): DEFINE VARIABLE curGrid AS Infragistics.Win.UltraWinGrid.UltraGrid. curGrid = CAST(sender,Infragistics.Win.UltraWinGrid.UltraGrid). IF STRING(e:KEYCODE) = "up" THEN DO: curGrid:PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction:ExitEditMode, false, false). curGrid:PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction:AboveCell, false, false). curGrid:PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction:EnterEditMode, false, false). e:handled = TRUE. END. ELSE IF STRING(e:KEYCODE) = "down" OR STRING(e:KEYCODE) = "return" THEN DO: curGrid:PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction:ExitEditMode, false, false). curGrid:PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction:BelowCell, false, false). curGrid:PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction:EnterEditMode, false, false). e:handled = TRUE. END. RETURN. END METHOD.
This does not work for the up/down keys. If I changed Above/BelowCell to Prev/NextCell, up/down keys work. However, the only reason that this works is because only a single col in the gird is editable. So, it's a bit of a hack.