Search code examples
wpfdatagriddevexpresscolumn-chooser

DevExpress DataGrid's ColumnChooser


I use AutoPopulateColumns system to display my structure on DataGrid. is there any propertie's Attribute to show Property on ColumnChooser window, not on the grid?

Thanks.


Solution

  • Ok, I can't find such default attribute, so I've created my own empty attribute, call it "ShowInColumnChooserAttribute".

    Mark all properties, that I don't need on dataGrid, but need on ColumnChooser with this attribute

    And in dataGrid's event "ColumnsPopulated" do the next:

            var hiddenList = new List<string>();
            var r = dataTable.ItemsSource.GetType().GetGenericArguments()[0];
            foreach (var prop in r.GetProperties())
                if (prop.GetCustomAttributes(typeof(ShowInColumnChooserAttribute), true).Length > 0)
                    hiddenList.Add(prop.Name);
            foreach (var column in ((DevExpress.Xpf.Grid.GridControl)sender).Columns)
                    column.Visible = !hiddenList.Contains(column.FieldName);
    

    I think that this is very easy and beautiful solution! Hope this'll help!