Guest User

Untitled

a guest
Jan 23rd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. <telerik:RadGridView x:Name="MyGridView" AutoGenerateColumns="True" AutoGeneratingColumn="MyGridView_OnAutoGeneratingColumn" ItemsSource="{Binding MyData}" />
  2.  
  3. private void MyGridView_OnAutoGeneratingColumn(object sender, GridViewAutoGeneratingColumnEventArgs e)
  4. {
  5. //Extra1: Ignore this event for certain columns
  6. if (e.Column.UniqueName.Contains("extra1"))
  7. {
  8. return;
  9. }
  10. //Extra2: Disable the generation of a column entirely
  11. if (e.Column.UniqueName.Equals("extra2"))
  12. {
  13. e.Cancel = true;
  14. return;
  15. }
  16.  
  17. //Place a CheckBox inside the header
  18. e.Column.Header = new StackPanel()
  19. {
  20. Orientation = Orientation.Vertical,
  21. Children =
  22. {
  23. new TextBlock()
  24. {
  25. Text = e.Column.UniqueName,
  26. Margin = new Thickness(2),
  27. HorizontalAlignment = HorizontalAlignment.Center
  28. },
  29. new CheckBox()
  30. {
  31. Margin = new Thickness(2),
  32. HorizontalAlignment = HorizontalAlignment.Center
  33. }
  34. }
  35. };
  36. }
  37.  
  38. private void MyButton_OnClick(object sender, RoutedEventArgs e)
  39. {
  40. var cols = new List<GridViewColumn>();
  41. foreach (var col in MyGridView.Columns)
  42. {
  43. var hc = MyGridView.ChildrenOfType<GridViewHeaderCell>().FirstOrDefault(q => q.Column != null && q.Column.UniqueName == col.UniqueName && q.Column.DisplayIndex == col.DisplayIndex);
  44. if (hc == null) continue;
  45. var cb = hc.FindChildByType<CheckBox>();
  46. if (cb != null && cb.IsChecked == true)
  47. cols.Add(col);
  48. }
  49. MessageBox.Show(string.Join(", ", cols.Select(q => q.UniqueName)));
  50. }
Add Comment
Please, Sign In to add comment