Question

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.

Was it helpful?

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;
                }
            }
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top