2

I am using a datagrid in WPF.
I need to update my graphics engine once the selection in Datagrid is complete.
How to know when user has completed the selection in datagrid.
The combinations are using MouseDown and UpEvents, KeyDown and Up events. Any ideas?

Gilad
  • 6,437
  • 14
  • 61
  • 119
Ayyappan Subramanian
  • 5,348
  • 1
  • 22
  • 44

1 Answers1

1

You can use the SelectedItem property to get the currently selected object, which you can then cast into the correct type.

Person person = (Person)myDataGrid.SelectedItem;

or bind into the SelectedItem property.

<Grid DataContext="MyViewModel">
    <DataGrid ItemsSource="{Binding Path=People}"
              SelectedItem="{Binding Path=SelectedPerson , Mode=TwoWay}"/>
</Grid>    

for Multiple selection please use this: http://grokys.blogspot.co.il/2012/02/mvvm-and-multiple-selection-part-iv.html

or even better WPF DataGrid multiselect binding

Also you can add a button "apply selection" and it would solve your problem

Community
  • 1
  • 1
Gilad
  • 6,437
  • 14
  • 61
  • 119
  • Thank u for the response. This solution work for single selection. What about multiselection. I want exactly when the user completes multiselection – Ayyappan Subramanian Feb 19 '15 at 21:58
  • Is there any way to know when the multi selection is complete? – Ayyappan Subramanian Feb 19 '15 at 22:13
  • you can add a delay between the clicks in the event and wait for lets say 2 seconds. that will probably be good enough to say the selection was completed, if not, just updated on each change and handle each selection like it was the last one. – Gilad Feb 19 '15 at 22:20