I've a VB.net WPF application that display data on a datagrid. I need to get the selected rows;
XAML
<DataGrid Grid.Column="1" Loaded="{s:Action RefreshMyTable}" Grid.ColumnSpan="5" Grid.Row="1" Grid.RowSpan="17" SelectionChanged="{s:Action test}" AutoGenerateColumns="True" ColumnWidth="*" SelectedValuePath="ID" SelectedItem="{Binding Path=SelectedItemDG, Mode=TwoWay}" ItemsSource="{Binding myCollection}">
VM
Public Property SelectedItemDG As New myObject
Public Property SelectedItemDGCollection As New BindableCollection(Of myObject)
Public Sub test(ByVal sender As Object, ByVal e As EventArgs)
SelectedItemDGCollection.Add(SelectedItemDG)
End Sub
Public Sub btntestmultiselection()
For Each x In SelectedItemDGCollection
Debug.WriteLine(x.ID)
Next
End Sub`
I can get the item selected if only one row is selected, but if many rows are selected in this way I get only the latest. I found some answers here that mention the property SelectedItems instead of SelectedItem, but I can't find it in wpf datagrid. Of course I would avoid code behind since I'm using mvvm. Any advice?