Home Forums WPF controls Xceed DataGrid for WPF Group by – hiding columns from main grid…

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #25784 |

    I would like to hide the grouped columns from the main grid when the user groups by those columns. Is this possible to do automatically, or do I need to write some code for this?

    Any recommendations?

    Imported from legacy forums. Posted by Kelly (had 1871 views)

    User (Old forums)
    Member
    Post count: 23064

    Ok… I found a solution to this:

    In my window’s constructor, I did:

    INotifyCollectionChanged ncc = dataGridControl1.GroupLevelDescriptions;
    ncc.CollectionChanged += new NotifyCollectionChangedEventHandler(ncc_CollectionChanged);

    For the collection changed handler, I did:

    void ncc_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
    {
    Debug.WriteLine(string.Format(“action: {0}\r\n+++NewItemCount: {1}\r\n+++OldItemCount: {2}\r\n+++NewStart: {3}\r\n+++OldStart: {4}”, e.Action, e.NewItems != null ? e.NewItems.Count: 0, e.OldItems != null ? e.OldItems.Count: 0, e.NewStartingIndex, e.OldStartingIndex));
    if (e.NewItems != null)
    {
    foreach (Xceed.Wpf.DataGrid.GroupLevelDescription gld in e.NewItems)
    {
    dataGridControl1.Columns[gld.FieldName].Visible = false;
    }
    }
    if (e.OldItems != null)
    {
    foreach (Xceed.Wpf.DataGrid.GroupLevelDescription gld in e.OldItems)
    {
    dataGridControl1.Columns[gld.FieldName].Visible = true;
    }
    }
    }

    Seems to work beautifully. Sorry for the spacing – can’t seem to figure out how to do it nicely in this forum.

    Imported from legacy forums. Posted by Kelly (had 3107 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.