Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get list of all selected cells #39

Open
Pyth0ff opened this issue Oct 9, 2019 · 4 comments
Open

Get list of all selected cells #39

Pyth0ff opened this issue Oct 9, 2019 · 4 comments

Comments

@Pyth0ff
Copy link

Pyth0ff commented Oct 9, 2019

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.

@JohanLarsson
Copy link
Member

Sounds useful even if not common. What type should be used for CellItems maybe ReadOnlyObservableCollection<object> is best.

@Pyth0ff
Copy link
Author

Pyth0ff commented Oct 9, 2019

Yes, ReadOnlyObservableCollection<object> sounds good.

@JohanLarsson
Copy link
Member

I'm not gonna have time anytime soon, do you feel like trying your hand at a PR?

@mennowo
Copy link
Contributor

mennowo commented Oct 19, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants