Gu.Wpf.DataGrid2D
Gu.Wpf.DataGrid2D copied to clipboard
Get list of all selected cells
It is currenly only possible via Selected.CellItem
to get an single cell item. I want to bind multiple selected cells to my ViewModel, which would require something like Selected.CellItems
.
Sounds useful even if not common. What type should be used for CellItems
maybe ReadOnlyObservableCollection<object>
is best.
Yes, ReadOnlyObservableCollection<object>
sounds good.
I'm not gonna have time anytime soon, do you feel like trying your hand at a PR?
A different approach to multi-selection - which is facilitated for example by ListView, might be to have an IsSelected property on the ViewModel, which can be set if the cell is selected. In the VM, you can then easily retrieve a complete list of selected items. I think this approach can also be applied with DataGrid: https://docs.microsoft.com/en-us/dotnet/api/system.windows.controls.datagridcell.isselected?view=netframework-4.8 For a ListView, it then looks like this:
<ListView.Resources>
<Style TargetType="ListViewItem">
<Setter Property="IsSelected" Value="{Binding Selected, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" />
</Style>
</ListView.Resources>
You can thus simply add a 'Selected' property or so to your VM. This should be applicable to DataGrid also. Of course, this presupposes you bind a ViewModel to the cells of the 2D GridView.