Please help me, Im trying to get the value of Cell[0] from the selected row in a SelectionChangedEvent.
I am only managing to get lots of different Microsoft.Windows.Controls and am hoping im missing something daft.
Hoping I can get some help from here...
private void datagrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Microsoft.Windows.Controls.DataGrid _DataGrid = sender as Microsoft.Windows.Controls.DataGrid;
}
I was hoping it would be something like...
_DataGrid.SelectedCells[0].Value;
However .Value isn't an option....
Many many thanks this has been driving me mad! Dan
pls, check if code below would work for you:
hope this helps, regards
Less code, and it works.
ColumnIndex is the index of the column you want to know.
Since you are using the "SelectionChanged", you can use the sender as a Data Grid:
I tried the answers posted here and were good, but gave me problems when started to hide columns in the DataGrid. This one works for me even when hiding columns. Hope it works for you too.
This will give you the current selected row in the DataGrid in WPF:-
Now to get the cell value just write
dtr[0]
,dtr["ID"]
, etc.