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

How to expand specific group in code?

1 Answer 1107 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tomislav Rakic
Top achievements
Rank 1
Tomislav Rakic asked on 02 Feb 2010, 05:30 PM
Hi,

I have hierarchical RadGridView where MasterGridViewTemplate.AutoExpandGroups is set to False. Code for binding is like this.
PatientGridView.DataSource = currentPatientList
GridGroupByExpression patientExpression = new GridGroupByExpression(); 
patientExpression.Expression = "FullName as FullName format \"{1}\" Group By OrderID"; 
PatientGridView.MasterGridViewTemplate.GroupByExpressions.Add(patientExpression); 

After binding I want to programatically expand some groups by certain condition. I have tried with following code but it doesn't work:

            foreach (GridViewRowInfo row in PatientGridView.Rows) { 
                if (someCondition == true) { 
                    row.IsExpanded = true
                    row.IsSelected = true
                    PatientGridView.GridNavigator.SelectRow(row); 
                } 
            } 


Can you advise how to programmatically expand specific group in RadGridView where all groups are collapsed by default?

Regards,
Tomislav

1 Answer, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 04 Feb 2010, 09:45 AM
Hi Tomislav Rakic,

Thank you for the question.

Please note that a hierarchical RadGridView is different than a grouped RadGridView. Your code snippet will work in you have a hierarchical RadGridView where there are master data records and child data records. However, if you have a grouped RadGridView, you can loop through the groups' header rows as it is shown below:
foreach(DataGroup group in this.radGridView1.Groups)
{
    // sample condition
    if (this.radGridView1.Groups.IndexOf(group) % 2 == 0)
    {
        group.HeaderRow.IsExpanded = true;
  
        // or simply
        group.Expand();
    }
}

For additional information, please refer to this article.

I hope this helps. If you have additional questions, feel free to contact me.

Greetings,
Nikolay
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Tags
GridView
Asked by
Tomislav Rakic
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Share this question
or