Search code examples
wpfwpfdatagrid

WPF DataGrid get selected row


Need to do some logic based on the current row selected. New to WPF before I would do something like this;

int i myDataGridView.CurrentCell.RowIndex

Now that is not available, what is best way to get selected row?


Solution

  • Use DataGrid.SelectedItem property. It gives the Selected Item on the DataGrid if SelectionMode is Single. Else DataGrid.SelectedItems gives the multiple selection if SelectionMode is Extended or Multiple