Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
960
Avoid tabstop on readonly cells
posted

Is it possible to achieve the subject? I have a grid with 3 columns, just one is editable, when the user is editing it would be nice to allow him to pass from an editable value to the next using a tab without stopping on the readonly fields.

And also, we can use the enter key as a mean to enter edit mode, is there the possibility to use the enter key to go down one cell? I already know that arrow keys are not exactly easy to implement...

thank you in advance.

  • 34810
    Offline posted

    Hello Sabrina,

    Thank you for your post.

    To prevent tab stop on editable columns in the XamGrid, I would recommend handling the PreviewKeyDown event and checking the e.Key property of the event arguments for Key.Tab. If the key pressed is the tab key, obtain the active cell from the XamGrid, using myGrid.ActiveCell. From the cell, you can get the rowIndex and the column that it sits in. If the cell is editing, I would recommend calling grid.ExitEditMode(false), then call grid.EnterEditMode on the cell that is directly beneath the active cell. This will be grid.Rows[rowIndex + 1].Cells[column]. You will also want to set IsSelected on this new cell to true as well, or the old active cell will appear selected.

    The process for the Enter key is very similar to the above. Check e.Key for Key.Enter, obtain the cell, row index, and column, and check whether it is editing or not. If it is, exit edit mode and enter edit mode on the cell below. If the cell is not in edit mode, you can just call grid.EnterEditMode(activeCell).

    A couple things to note: you should mark the PreviewKeyDown event as handled after each of the above operations, so that the grid does not get into the actual KeyDown event for these keys. Also, I have placed the code for selected the next cell down in a try-catch statement here, so that the exception that would be thrown on the last cell in the grid gets caught.

    I have attached a sample project to demonstrate the above. I also wasn't sure if you wanted the custom tab navigation when not in edit mode, so I included it, but it is  currently commented out. Also, implementing the arrow keys can be achieved in a very similar fashion to the above.

    Please let me know if you have any other questions or concerns on this matter.

    Sincerely,
    Andrew
    Associate Developer
    Infragistics Inc.
    www.infragistics.com/support

    XamGridTabStopCase.zip