Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. List<MyObject> _localCollection = new List<MyObject>();
  2. List<MyObject> LocalCollection
  3. {
  4. get { return _localCollection; }
  5. set
  6. {
  7. _localCollection = value;
  8. OnPropertyChanged("LocalCollection");
  9. }
  10. }
  11.  
  12. <GridView Name="grdItems">
  13. <GridViewColumn>
  14. <GridViewColumn.Header>
  15. <CheckBox/>
  16. </GridViewColumn.Header>
  17. <!--Column Template-->
  18. <GridViewColumn.CellTemplate>
  19. <DataTemplate>
  20. <StackPanel Orientation="Horizontal">
  21. <CheckBox Tag="{Binding ObjID}"
  22. IsChecked="{Binding ToRemove, Mode=OneWay}"
  23. Checked="SelectRelative" />
  24. </StackPanel>
  25. </DataTemplate>
  26. </GridViewColumn.CellTemplate>
  27. </GridViewColumn>
  28.  
  29. private void SelectRelative(object sender, RoutedEventArgs e)
  30. {
  31. Dispatcher.BeginInvoke((Action)(() =>
  32. {
  33. //Get the Object Id we need
  34. int selectedId = Convert.ToInt32(((CheckBox)sender).Tag);
  35. //Get all objects that share this ID
  36. List<MyObjects> objLst = new List<MyObjects>(((IEnumerable<MyObjects>)grdItems.ItemsSource));
  37.  
  38. //Clear the local collection property of our items used in the items source
  39. LocalCollection.Clear();
  40. //Remove the items source since we are updating it
  41. grdItems.ItemsSource = null;
  42. //Go through each item in the list and if the object id's match select them to remove
  43. foreach(var item in objLst)
  44. {
  45. if(item.ObjId == selectedId)
  46. item.ToRemove = true;
  47. //Add the object to our property
  48. LocalCollection.Add(item);
  49. }
  50. //Re-establish the item source with our new collection
  51. grdItems.ItemsSource = LocalCollection;
  52. }));
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement