Search code examples
c#wpfxamlwpftoolkitxceed-datagrid

Xceed DataGridControl how to hide column in groupdescription?


I'm trying to hide a column from the DataGridControl when it is a GroupDescription. Is there some easy way to do this that I don't know about?

The Visible property of the Columns appears to be a good place to start, but I can't figure out what I could bind to the XAML for it to behave like I want.


Solution

  • If anyone is interested, this is how I accomplished this:

    public class CustomDataGridControl : DataGridControl
    {
        public CustomDataGridControl()
        {
            var groupLevelDescriptions = (INotifyCollectionChanged)this.GroupLevelDescriptions;
            groupLevelDescriptions.CollectionChanged += collectionChanged_CollectionChanged;
        }
    
        void collectionChanged_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.NewItems != null)
            { 
                foreach (var item in e.NewItems)
                {
                    var groupLevelDescription = item as GroupLevelDescription;
    
                    foreach (var column in this.Columns)
                    {
                        if (column.FieldName == groupLevelDescription.FieldName)
                            column.Visible = false;
                    }
                }
            }
    
            if (e.OldItems != null)
            {
                foreach (var item in e.OldItems)
                {
                    var groupLevelDescription = item as GroupLevelDescription;
    
                    foreach (var column in this.Columns)
                    {
                        if (column.FieldName == groupLevelDescription.FieldName)
                            column.Visible = true;
                    }
                }
            }
        }
    }