This is a migrated thread and some comments may be shown as answers.

Expand / Collapse issue after adding rows

4 Answers 128 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Alain
Top achievements
Rank 1
Alain asked on 03 Jul 2011, 09:11 AM
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

4 Answers, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 06 Jul 2011, 11:54 AM
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!

0
Alain
Top achievements
Rank 1
answered on 07 Jul 2011, 07:21 PM
It works fine.

Thanks for your reply.
Alain
0
subbarayan
Top achievements
Rank 1
answered on 12 Aug 2011, 07:37 AM
Hi

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

0
Svett
Telerik team
answered on 16 Aug 2011, 03:00 PM
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 >>

Tags
GridView
Asked by
Alain
Top achievements
Rank 1
Answers by
Svett
Telerik team
Alain
Top achievements
Rank 1
subbarayan
Top achievements
Rank 1
Share this question
or