Skip to main content Skip to footer

ColumnPicker in C1DataGrid

The ColumnPicker functionality is helpful in toggling the visibility of columns at runtime. This blog gives a very simple code to add this in C1DataGrid. Below is the simple code which adds the functionality to the C1DataGrid for both WPF and Silverlight.

 var _dgmenu = new C1ContextMenu();  
 var cpitem = new C1MenuItem() { Header = "Column Picker" };  
 cpitem.Click += (s, e) =>  
 {  
    var window = new C1Window() { Header = "Column Picker", Height = 300, Width = 300, ShowMaximizeButton = false, ShowMinimizeButton = false };  
    var columns = new ListBox();  
    columns.ItemTemplate = this.Resources["lbitemtemplate"] as DataTemplate;  
    columns.ItemsSource = dg.Columns;  //dg is C1DataGrid  
    window.Content = columns;  
    window.CenterOnScreen();  
    window.Show();  
 };  
 _dgmenu.Items.Add(cpitem);  
 C1ContextMenuService.SetContextMenu(dg, _dgmenu);

Please refer to the attached sample for detailed implementation. Download Sample

MESCIUS inc.

comments powered by Disqus