Sorry for posting 2 different issues in one thread, but they are kinda intertwined in my situation here.
The first thing I'm wanting to do is make it so the Enter key within the RadGridView is treated like the Tab key instead. I was able to successfully do this via a custom KeyboardCommandProvider, by making it call DefaultKeyboardCommandProvider's ProvideCommandsForKey with Key.Tab is the key was Key.Enter.
The second thing I'm wanting to do is specially handle what happens with new rows. There are 3 columns in the grid and the first 2 are being validated via INotifyDataErrorInfo while the last has no validation. I'm wanting to do the following with a new row:
- On starting the new row, the first column is always selected. (I was able to do this without issues inside the AddingNewDataItem event, so this isn't a problem.)
- On attempting to leave the first cell, I want to check the value and prevent progression if that value exists elsewhere in the same column. (I was able to do this without issues inside the CellValidating event, so this isn't a problem either.)
- When pressing Enter or Tab in the last column, I want to get out of edit mode, select the new row after it has been added to the grid, and then scroll down to that new row. (This is where I am having all my issues, as I'll explain further below.)
What I've tried doing is inside of my custom KeyboardCommandProvider, if the key is Key.Tab or Key.Enter, Shift isn't being held down, and if I am in the last column (checking the grid's current column DisplayIndex and checking if it is 2) and in a new row (which I check by seeing if my view model's current selection is null, which I set inside the AddingNewDataItem event), then I was trying to remove the default actions of select current unit and begin edit (so the only action left is move next) and add in a custom command to attempt to select the new row (which I've stored inside of the RowEditEnded event).
My custom command for attempting the new row selection consists of canceling the grid view's edit, setting the CurrentCellInfo of the grid to the new item in the first column, and then using ScrollIntoViewAsync for the same item and column.
The issues I'm running in to:
- I originally was not removing Tab's default commands or calling my custom command, and instead was trying to do the above stuff from the custom command within the SelectionChanged event. As I was storing the row inside the RowEditEnded event, I was also trying to change the current selected item in my view model through that event, which meant that running the commands in SelectionChanged only partially worked because the rest of the grid view's code for the RowEditEnded event after my callback would change the CurrentCellInfo.
- I then tried the method I explained above with changing the commands for the Tab key, and if I press Tab instead of Enter, I've been finding that sometimes the grid view will retain focus and run my custom command and other times it'll move focus to the next control in the window and never run my custom command as a result.
- In the cases when the above does retain focus on the grid view, while I think I solved the issues with CurrentCellInfo, scrolling the grid view to the new row has been hit or miss. Sometimes it works and the success callback is called, sometimes it doesn't work and the failure callback is called instead. I've also noticed that while the current cell has the proper selection border on it, I've also seen a different cell in the grid have the focus border on it.
- The last thing I tried was removing all the commands entirely if the Tab key is pressed (but leave things as above for the Enter key, that is only the move next and my custom command) in that same situation, but because of that, I've found that the grid view loses focus.
If need be, I can provide a minimal example of what I've currently got that isn't working.