Ok after doing reverse engineering and a little pixie dust of reflection, one can do this operation on SelectedCells
(at any point) to get all (regardless of selected on one row or many rows) the data from one to many selected cells:
MessageBox.Show(
string.Join(", ", myGrid.SelectedCells
.Select(cl => cl.Item.GetType()
.GetProperty(cl.Column.SortMemberPath)
.GetValue(cl.Item, null)))
);
I tried this on text (string) fields only though a DateTime field should return a value the initiate ToString()
. Also note that SortMemberPath
is not the same as Header
so that should always provide the proper property to reflect off of.
<DataGrid ItemsSource="{Binding MyData}"
AutoGenerateColumns="True"
Name="myGrid"
IsReadOnly="True"
SelectionUnit="Cell"
SelectionMode="Extended">