user2891892
user2891892

Reputation:

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?

Upvotes: 2

Views: 6880

Answers (2)

Nitin Purohit
Nitin Purohit

Reputation: 18578

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

Upvotes: 1

Josh
Josh

Reputation: 1356

Try this:

SomeObject someObject = (SomeObject)myDataGridView.SelectedItem

Upvotes: 0

Related Questions