Expanding all groups, including nested, in an xceed DataGridControl

馋奶兔 提交于 2019-12-12 03:36:13

问题


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.


回答1:


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);
        }
    }
}


来源:https://stackoverflow.com/questions/36519828/expanding-all-groups-including-nested-in-an-xceed-datagridcontrol

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!