2016-04-09 44 views
0

我可以展開一個組,但我的應用程序使用嵌套的分組。我試圖做一些如下:擴展所有組,包括嵌套,在一個xceed DataGridControl

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

GridControl這裏是一個DataGridControl。即使我有嵌套組,這裏的項目只會顯示1個項目,但在循環內部,組可以在其VirtualizedItems中看到其子組,但不會在其Items中看到它的子組。我不認爲我可以訪問VirtualizedItems。

回答

1

下面顯示的代碼片段可能適用於您的場景。我能夠使用它來擴展/摺疊所有組和子組。這適用於我們的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); 
     } 
    } 
}