Search code examples
wpfdatagridwpfdatagridhittest

Is there a datagrid mouse down hit test to get the row and column index of the click?


With Winforms' DataGridView, one could use HitTest to determine the column and row index of the mouse down (and other events).

Dim hti As DataGridView.HitTestInfo = sender.HitTest(e.X, e.Y)

Is there something similar with WPF's DataGrid? I need to get the row and column indexes for the MouseLeftButtonDown event.


Solution

  • It's a bit more complicated than this but the following links should be helpful in getting the index of the row and column.

    WPF DataGrid - detecting the column, cell and row that has been clicked: http://blog.scottlogic.com/2008/12/02/wpf-datagrid-detecting-clicked-cell-and-row.html

    WPF DataGrid - get row number which mouse cursor is on

    You will have to use the VisualTreeHelper class to traverse the Visual elements that make up the DataGrid as explained above.