I\'m trying to get the values of each column of a selected row in a DataGrid. This is what I have:
private void dataGrid1_CellEditEnding(object sender, DataG
I believe the reason there's no straightforward property to access the selected row of a WPF DataGrid is because a DataGrid's selection mode can be set to either the row-level or the cell-level. Therefore, the selection-related properties and events are all written against cell-level selection - you'll always have selected cells regardless of the grid's selection mode, but you aren't guaranteed to have a selected row.
I don't know precisely what you're trying to achieve by handling the CellEditEnding event, but to get the values of all selected cells when you select a row, take a look at handling the SelectedCellsChanged event, instead. Especially note the remarks in that article:
You can handle the SelectedCellsChanged event to be notified when the collection of selected cells is changed. If the selection includes full rows, the Selector.SelectionChanged event is also raised.
You can retrieve the AddedCells and RemovedCells from the SelectedCellsChangedEventArgs in the event handler.
Hope that helps put you on the right track. :)
DataGrid get selected rows' column values it can be access by below code. Here grid1 is name of Gride.
private void Edit_Click(object sender, RoutedEventArgs e)
{
DataRowView rowview = grid1.SelectedItem as DataRowView;
string id = rowview.Row[0].ToString();
}