Expand / Collapse issue after adding rows

5 posts, 0 answers
  1. Alain
    Alain avatar
    13 posts
    Member since:
    Mar 2011

    Posted 03 Jul 2011 Link to this post

    Dear Tekerik Team,


    I'm using the following code (found on this forum) to expand / collapse a self referencing hierarchy grid:

    RadGridView1.TableElement.BeginUpdate()

    For Each row1 As GridViewDataRowInfo In RadGridView1.Rows

    row1.IsExpanded = True

     

    Next

    RadGridView1.TableElement.EndUpdate()


    While the code works after the data are first loaded, it only collapses child rows when I add a new row to the dataset.  I wonder if there is another method to collapse / expand all rows.

    In the same vein and if I add a parent row to the self referencing hierarchy grid, the following code does not start the edit:

    Dim

     

    lastRow As GridViewRowInfo = RadGridView1.Rows(RadGridView1.Rows.Count - 1)

     

    lastRow.EnsureVisible()

    lastRow.IsSelected =

    True

     

    lastRow.Cells(

    "Items").BeginEdit()

     


    The above code would however start the edit on a child row. Is there any other method for a parent row?


    Best regards,
    Alain
  2. Svett
    Admin
    Svett avatar
    728 posts

    Posted 06 Jul 2011 Link to this post

    Hi Alain,

    In hierarchy mode, each row has child rows. You can get them by accessing the ChildRows collection of the parent row. Hence, you can use the following code snippet as a sample:

    GridViewRowInfo row = this.radGridView1.ChildRows[0];
    row.IsExpanded = true;
     
    GridViewRowInfo lastChildRow = row.ChildRows[row.ChildRows.Count - 1];
    lastChildRow.IsCurrent = true;
    lastChildRow.IsSelected = true;

    Kind regards,
    Svett
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  3. Alain
    Alain avatar
    13 posts
    Member since:
    Mar 2011

    Posted 07 Jul 2011 Link to this post

    It works fine.

    Thanks for your reply.
    Alain
  4. subbarayan
    subbarayan avatar
    20 posts
    Member since:
    Oct 2008

    Posted 12 Aug 2011 Link to this post

    Hi

       how to collapse all other rows when i expand a row at mastertemplete(parent row).
    thanks.

  5. Svett
    Admin
    Svett avatar
    728 posts

    Posted 16 Aug 2011 Link to this post

    Hi Subbarayan,

    You should use the ChildViewExpanded event of RadGridView to achieve that. You can use the following code snippet as a sample:

    private void radGridView1_ChildViewExpanded(object sender, Telerik.WinControls.UI.ChildViewExpandedEventArgs e)
    {
        if (e.IsExpanded)
        {
            GridViewTemplate template = e.ParentRow.ViewTemplate;
     
            foreach (GridViewRowInfo row in template.Rows)
            {
                if (row != e.ParentRow)
                {
                    row.IsExpanded = false;
                }
            }
        }
    }

    I hope this helps. 

    Greetings,
    Svett
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Back to Top