<sfGrid:SfDataGrid x:Name="dataGrid"
AutoGenerateColumns="True"
ItemsSource="{Binding OrdersInfo}"
SelectionMode="Multiple">
<b:Interaction.Behaviors>
<b:BehaviorCollection>
<b:EventToCommand Command="{Binding SelectionCommand}"
CommandParameter="{x:Reference Name=dataGrid}"
EventName="SelectionChanged" />
</b:BehaviorCollection>
</b:Interaction.Behaviors>
</sfGrid:SfDataGrid>
// In ViewModel.cs
public ViewModel()
{
selectionCommand = new Command<SfDataGrid>(onSelectionChanged);
selectedItems = new ObservableCollection<object>();
}
private Command<SfDataGrid> selectionCommand;
public Command<SfDataGrid> SelectionCommand
{
get { return selectionCommand; }
set { selectionCommand = value; }
}
private ObservableCollection<object> selectedItems;
public ObservableCollection<object> SelectedItems
{
get { return selectedItems; }
set { selectedItems = value; }
}
private void onSelectionChanged(SfDataGrid obj)
{
//you can get the selected items in the datagrid
selectedItems = obj.SelectedItems;
} |
How can DgBilledItems selected items contains the selected items from DgItems?
- user clicks on Add Item button in Main view
- Add items view opens and user select items and click on done.
- Main view adds the item selected by getting parameter passed through the Add items view
- now when user select items in Main view. The list selected items also contains the items that are selected in Add items view. How is that possible?
How to clear the previous selected items?
//You can clear all the previous items in the SelectedItems
this.dataGrid.SelectedItems.Clear();
//You can remove any particular selected item in the SelectedItems
this.dataGrid.SelectedItems.RemoveAt(1); |