Home Forums WinForms controls Xceed Grid for WinForms Programatically close/expand groups? Reply To: Programatically close/expand groups?

User (Old forums)
Member
Post count: 23064

Here’s some code I use to collapse all the groups (also groups inside groups) programmatically:
<code>public static void CollapseAllGroups(GridControl grid)
{
if (grid == null) throw new ArgumentNullException(“grid”);
foreach(Group group in grid.Groups)
CollapseGroups(group);
}

static void CollapseGroups(Group group)
{
foreach(Group subGroup in group.Groups)
CollapseGroups(group);
group.Collapse();
}</code>

And expanding is just as easy:

<code>public static void ExpandAllGroups(GridControl grid)
{
if (grid == null) throw new ArgumentNullException(“grid”);
foreach(Group group in grid.Groups)
ExpandGroups(group);
}

static void ExpandGroups(Group group)
{
foreach(Group subGroup in group.Groups)
ExpandGroups(group);
group.Expand();
}</code>

Imported from legacy forums. Posted by Tommy (had 798 views)