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

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #15088 |

    This is probably a very dumb question. I want the form containing my grid to open with the groups in the grid all closed up (I have only one group row). I can’t see a property that seems to specify this, or a method on the group manager row that would let me do it after the data is loaded. Surely this is possible? If so, how do I do it?

    Imported from legacy forums. Posted by Steve (had 4768 views)

    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)

    User (Old forums)
    Member
    Post count: 23064

    Thanks Tommy. I had been looking for properties or methods on the GroupManager row, but then discovered that that there is also a Group object (not immediately obvious), which does the trick.

    Imported from legacy forums. Posted by Steve (had 3220 views)

    User (Old forums)
    Member
    Post count: 23064

    I tried this without success. Does this work in v3.1?

    Imported from legacy forums. Posted by Giuliano (had 2119 views)

    User (Old forums)
    Member
    Post count: 23064

    Mate,

    If I am writing something I wouldwrite like following

    Just Drag and Drop Button on Form and attach Click Event to it.

    Write a rec method to the job for you..

    THis will handle collapse or expand anything upto any level..

    private void button1_Click(object sender, EventArgs e)
        {
            bool collapse = (String.Compare(button1.Text, “Collapse All”, true) == 0);
            CollapseOrExpand(collapse,gridControl1.Groups);
            button1.Text = (collapse) ? “Expand All” : “Collapse All”;
        }

        private void CollapseOrExpand(bool collapse, ReadOnlyGroupList group)
        {
           foreach(Group currentgroup in group)
           {
               if (currentgroup.Groups.Count > 0)
               {
                   CollapseOrExpand(collapse, currentgroup.Groups);
               }
               else
               {
                   currentgroup.Collapsed = collapse;
               }
           }
        }

     

    Imported from legacy forums. Posted by NR (had 380 views)

    User (Old forums)
    Member
    Post count: 23064

    There is a typo in Tommy’s code.  In both the CollapseGroups and ExpandGroups method, the recursive call to the CollapseGroups() is done with the wrong parameter.  It is called with group, but it should be called with subGroup .

     i.e.:

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

    Imported from legacy forums. Posted by André (had 531 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks Nimit  for the feedback and thanks André for the clarification.

    Imported from legacy forums. Posted by Giuliano (had 2792 views)

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.