Derek Meyer
Derek Meyer

Reputation: 507

Expanding all groups, including nested, in an xceed DataGridControl

I am able to expand a single group fine, but my app uses nested groupings. Im attempting to do something as follows:

                foreach (CollectionViewGroup group in GridControl.Items.Groups)
                {
                    if (group != null)
                        GridControl.ExpandGroup(group);
                }

GridControl here is a DataGridControl. Even if i have nested groups, items here will only show 1 item, but inside the loop, the group can see its subgroup in its VirtualizedItems, but not in its Items. I dont think i can access the VirtualizedItems.

Upvotes: 0

Views: 878

Answers (1)

Diane-Xceed
Diane-Xceed

Reputation: 319

Perhaps the code snippet shown below will work in your scenario. I was able to use it to expand/collapse all groups and sub-groups. This worked in both our DataVirtualization sample and with a grid that didn't use data virtualization. Also, I didn't have to scroll down first, even with a very large number of rows.

private void btnCollapseAllGroups_ButtonClick(object sender, RoutedEventArgs e)
{
    CollapseOrExpandAll(null, true);
}

private void btnExpandAllGroups_ButtonClick(object sender, RoutedEventArgs e)
{
    CollapseOrExpandAll(null, false);
}

private void CollapseOrExpandAll(CollectionViewGroup inputGroup, Boolean bCollapseGroup)
{
    IList<Object> groupSubGroups = null;

    // If top level then inputGroup will be null
    if (inputGroup == null)
    {
        if (grid.Items.Groups != null)
            groupSubGroups = grid.Items.Groups;
    }
    else
    {
       groupSubGroups = inputGroup.GetItems();
    }

    if (groupSubGroups != null)
    {

        foreach (CollectionViewGroup group in groupSubGroups)
        {
            // Expand/Collapse current group
            if (bCollapseGroup)
                grid.CollapseGroup(group);
            else
                grid.ExpandGroup(group);

            // Recursive Call for SubGroups
            if (!group.IsBottomLevel)
                CollapseOrExpandAll(group, bCollapseGroup);
        }
    }
}

Upvotes: 1

Related Questions