Álvaro García
Álvaro García

Reputation: 19396

How to know the selected items in a DataGrid with extended selection mode?

I have a datagrid in a WPF project, and I am using the MVVM pattern. I would like to be able to select multiple rows and in code, to know wich rows are selected. To do that, I set in the dataGrid the extended value to the selectionMode property.

I am using also MVVM light to convert the event selectionChanged to a command, and I pass the SelectedItems property as parameter.

I notice the following. When I select the first row with the mouse, in the slectionChanged method I receive one row, it's ok. For example, this is the first row, for example.

Now, I press ctrl key and select the third row. In the event I receive 0 rows. If now I select the second row, then I receive 1 row, the second row.

So it seems that I only can receive the last row, but only if there is a continue block of rows, if I selected alternated rows, then I receive 0 rows.

How can I know the selected rows when I select alternate rows? And How can I know all the selected rows when I select a conitnue block of rows?

Thanks.

Upvotes: 1

Views: 1335

Answers (1)

yo chauhan
yo chauhan

Reputation: 12315

Make sure your Datagrid Property > SelectionUnit is Row

.I hope this will help.

Upvotes: 4

Related Questions