Search code examples
c#wpfdatagrid

row index of DataGridCell


I have a DataGrid and on a Click I want to find index of a clicked cell. I found a way to get DataGridCell, and DataGridCellInfo, but there is only column index in it.

How to get row index? I cannot find a way to get it.


Solution

  • Found an answer! For the future people who will look for it:

    DataGridRow r2 = DataGridRow.GetRowContainingElement(cell);
    int rowindex = r2.GetIndex();