Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <telerik:RadGridView x:Name="MyGridView" AutoGenerateColumns="True" AutoGeneratingColumn="MyGridView_OnAutoGeneratingColumn" ItemsSource="{Binding MyData}" />
- private void MyGridView_OnAutoGeneratingColumn(object sender, GridViewAutoGeneratingColumnEventArgs e)
- {
- //Extra1: Ignore this event for certain columns
- if (e.Column.UniqueName.Contains("extra1"))
- {
- return;
- }
- //Extra2: Disable the generation of a column entirely
- if (e.Column.UniqueName.Equals("extra2"))
- {
- e.Cancel = true;
- return;
- }
- //Place a CheckBox inside the header
- e.Column.Header = new StackPanel()
- {
- Orientation = Orientation.Vertical,
- Children =
- {
- new TextBlock()
- {
- Text = e.Column.UniqueName,
- Margin = new Thickness(2),
- HorizontalAlignment = HorizontalAlignment.Center
- },
- new CheckBox()
- {
- Margin = new Thickness(2),
- HorizontalAlignment = HorizontalAlignment.Center
- }
- }
- };
- }
- private void MyButton_OnClick(object sender, RoutedEventArgs e)
- {
- var cols = new List<GridViewColumn>();
- foreach (var col in MyGridView.Columns)
- {
- var hc = MyGridView.ChildrenOfType<GridViewHeaderCell>().FirstOrDefault(q => q.Column != null && q.Column.UniqueName == col.UniqueName && q.Column.DisplayIndex == col.DisplayIndex);
- if (hc == null) continue;
- var cb = hc.FindChildByType<CheckBox>();
- if (cb != null && cb.IsChecked == true)
- cols.Add(col);
- }
- MessageBox.Show(string.Join(", ", cols.Select(q => q.UniqueName)));
- }
Add Comment
Please, Sign In to add comment