Depending on the value of the first cell, I want to move to a specific cell of the AddRow after pressing TAB. I use NextCellByTab action to go to the third or fourth cell. I can see the third or fourth cell being selected and then the second cell is finally selected.
I do the check of the first cell's value inside BeforeExitEditMode and sets a flag that I check inside AfterExitEditMode where I call the action NextCellByTab. How do I override the destination cell determined by the TAB key?
I'm not trying to fully override the TAB behavior of the grid just for the first cell.
I would use the BeforePerformAction method. Check for an action of NextCellByTab. You can use the grid's ActiveRow and ActiveCell properties to determine which cell you are in, and then (optionally) cancel the action and set focus to whatever cell you want.
I tried that approach; however, PerformAction doesn't seem to fire when there is an embedded control in the cell.
Oh, so you are using the UltraControlContainerEditor? That complicates things, because the embedded EditorControl handles the tab key and not the grid.
If you knew the next cell before the user pressed the Tab key, you could handle this by using the TabIndex property on the column.
If not, then I'm not sure there is a good way to handle this. Using the edit mode events probably isn't a good solution because these events will fire when the user clicks outside the cell, and I assume you only want to override the Tab behavior, not mouse behavior.
I suppose if your embedded control is a UserControl or a derived control of your own creation, you might be able to handle the tab key on the control itself.
I was able to determine within the UserControl when the user pressed the TAB. When the user presses the TAB key;
- I set a variable.- Inside the BeforeExitEditMode, I check the flag(if TAB was pressed) and set the column tabstop of the second column to false.- Then in AfterExitEditMode, I call NextCellByTab.
Somehow the grid is still storing the second column as the destination cell. When I debug I can see the focus goes to the third/fourth cell after the NextCellByTab then suddenly the focus goes back to the second column.
However when I don't call NextCellByTab, the focus doesn't go anywhere not even to the second column.
Any ideas?
My guess is that your code is working, but that the grid or the editor is still processing the tab key. What event are you using to trap the tab key? KeyDown and KeyUp both have a Handled flag on the event args that you could set to true and that should prevent the key from being processed by the grid. Then you can simple set the ActiveCell in the grid to whatever cell you want.
I tried stopping the Tab key inside the UserControl using the ProcessCmdKey, and it looks promising. It no longer switch back to the second column after I call NextCellByTab.
Thanks,