【问题标题】:Expanding all groups, including nested, in an xceed DataGridControl在 xceed DataGridControl 中展开所有组,包括嵌套组
【发布时间】:2016-04-09 16:46:35
【问题描述】:

我可以很好地扩展单个组,但我的应用程序使用嵌套分组。我试图做如下事情:

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

这里的GridControl 是一个DataGridControl。即使我有嵌套组,这里的项目也只会显示 1 个项目,但在循环内,该组可以在其 VirtualizedItems 中看到其子组,但在其 Items 中看不到。我不认为我可以访问 VirtualizedItems。

【问题讨论】:

    标签: c# datagrid xceed


    【解决方案1】:

    也许下面显示的代码 sn-p 将适用于您的场景。我能够使用它来展开/折叠所有组和子组。这在我们的 DataVirtualization 示例和不使用数据虚拟化的网格中都有效。此外,我不必先向下滚动,即使行数非常多。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-11-20
      • 2011-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-03
      • 1970-01-01
      相关资源
      最近更新 更多