在xceed DataGridControl中扩展所有组,包括嵌套

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

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

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

也许下面显示的代码段可以在您的方案中使用。 我能够用它来扩展/折叠所有组和子组。 这在我们的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 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); } } }