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

How To Select Grouped Rows / Header Values?

1 Answer 259 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jason_G
Top achievements
Rank 1
Jason_G asked on 09 Dec 2009, 08:32 PM
HI,
can't find the answer to this anywhere so hope you can help.

I want to programatically expand a group when the user clicks on the group header (not just on the expand icon/button) and subsequently select all the rows in the group (multiselect is true already.)
I know I can use Groups[0].Expand() and use the Rows collection, but I can't find any way to get the index of the group when the user clicks on the group header.

I can detect that the user has selected a group header row by checking the type of the CurrentRow or using e.CurrentRow in CurrentRowChanged, but can't get any further.

I also want to get a value from the group header - e.g. if the GroupByExpression groups on CustomerName, how do I find the value of CustomerName when the user selects a Group Header row?

Many Thanks,
Jason

1 Answer, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 15 Dec 2009, 08:33 AM
Hi Jason_G,

A possible implementation for the described scenario is to use MouseDown event and GetElementAtPoint method. Please, consider the following code-block as an example:
void radGridView1_MouseDown(object sender, MouseEventArgs e)
{
    GridCellElement cellElement = this.radGridView1.ElementTree.GetElementAtPoint(e.Location) as GridCellElement;
    if (cellElement != null && !(cellElement is GridGroupExpanderCellElement) && cellElement.Parent is GridGroupHeaderRowElement)
    {                
        GridGroupHeaderRowElement groupRow = (GridGroupHeaderRowElement)cellElement.Parent;
        ((GridViewGroupRowInfo)groupRow.RowInfo).Group.Expand();
        object value = ((GridViewGroupRowInfo)groupRow.RowInfo).Group.Aggregates[0].Value;
        GridViewRowInfo[] childRows = ((GridViewGroupRowInfo)groupRow.RowInfo).Group.GetRows();
        foreach (var row in childRows)
        {
            row.IsSelected = true;
        }
  
        RadMessageBox.Show(String.Format("\"{0}\" has expanded and its child rows are selected", value));
    }
}

 

I hope this helps. Do not hesitate to contact me again if you have other questions.

Regards,
Martin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Jason_G
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
Share this question
or