Home Forums WPF controls Xceed DataGrid for WPF Handling Key.Home and Key.End

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #22800 |

    I’m working with a DataGridControl that has the following properties:

    myDataGridControl.SelectionMode = SelectionMode.Single
    myDataGridControl.ReadOnly = True
    myDataGridControl.CellEditorDisplayConditions = CellEditorDisplayConditions.None
    myDataGridControl.NavigationBehavior = NavigationBehavior.RowOnly

    When an item (a datarow) is selected I can use Key.Up and Key.Down to select the previous or next item.

    But I have a requirement to also handle Key.Home and Key.End to select the first row or the last row in the DataGridControl.

    I tried doing it this way:

    Private Sub myDataGridControl_PreviewKeyDown(ByVal sender As Object, ByVal e As System.Windows.Input.KeyEventArgs) Handles myDataGridControl.PreviewKeyDown
    Select Case e.Key
    Case Key.Home
    myDataGridControl.SelectedItem = myDataGridControl.Items.Item(0)
    Case Key.End
    myDataGridControl.SelectedItem = myDataGridControl.Items.Item(myDataGridControl.Items.Count – 1)
    End Select
    e.Handled = False
    End Sub

    I doesn’t really work, here are the problems:

    1) When I press Key.Home I can see the first row being selected. But if I press Key.Down instead of having the second row selected the focus goes back to whatever row I was in before the Key.Home and the next row after that is now selected.

    2) When I press Key.End I don’t see any row being selected. My guess is that this is due to virtualisation, but I have no clue how to force the DataGridControl to show the last row.

    Does anyone have any suggestions on how to implement the above requirements for handling Key.Home and Key.End?

    On a separate note, since the DataGridControl handles Key.Up and Key.Down out of the box, is there a reason why it wouldn’t handle Key.Home and Key.End as well?

    Imported from legacy forums. Posted by Emmanuel (had 2422 views)

    Xceed Support
    Member
    Post count: 5658

    The data grid control does handle the Key.Up and Key.Down, they are however used to navigate to the first and last column (but since you are using NavigationMode of RowOnly, they are “innefective”).

    As a side node, we did hook the CTRL-PageUp and CTRL-PageDown to achieve the same result as the one you obtained… So if you have no hard requirements of using the Home/End keys, you can have “out of the box” solution for your need.

    Finally, if you use the CurrentItem property instead of the SelectedItem, it should start working as expected.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 202 views)

    User (Old forums)
    Member
    Post count: 23064

    Ah! It all makes sense now, thanks again Marcus.

    As a side remark, I wonder if there should be two sets of keyboard hookups which would depend on the NavigationMode.

    Specifically in this example: hooking up CTRL-PageUp and CTRL-PageDown when not in RowOnly mode makes a lot of sense. But when in RowOnly mode making them “innefective” doesn’t make sense and the standard in this mode is Key.Up and Key.Down.

    Maybe as a future feature we could dynamically load the key mappings depending on the mode we’re on?

    Imported from legacy forums. Posted by Emmanuel (had 3820 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.