0

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.

4

1 回答 1

0

如果有人有兴趣,我就是这样做的:

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;
                }
            }
        }
    }
}
于 2014-04-04T13:03:51.233 回答