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

How can I determine which childrow was click in a heirarchical gridview

3 Answers 191 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Eddie Harvey
Top achievements
Rank 1
Eddie Harvey asked on 03 Sep 2010, 02:22 PM
I have a GridView that has a child template and a relation. I can populate both without an problems at all. When I expand to view the childrows and click/double click one of them I need to open a secondary form that displays some additional data. In order to do that I need to be able to determine the properties of that childrow which was clicked. However, I keep getting the row in the  MasterTemplate... how do I go about this.

3 Answers, 1 is accepted

Sort by
1
Alexander
Telerik team
answered on 08 Sep 2010, 05:18 PM
Hello Eddie Harvey,

Thank you for your question.

You can find out whether a RadGridView row belongs to the Parent or Child template using the following code snippet:
private void radGridView1_CellDoubleClick(object sender, GridViewCellEventArgs e)
{
    if (e.Row.ViewTemplate == this.radGridView1.MasterTemplate)
    {
        // it is a Parent row
    }
    else
    {
        // it is a Child row
    }
}

I hope it helps.

Best regards,
Alexander
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Fernando Moragrega
Top achievements
Rank 1
answered on 17 Sep 2010, 10:18 AM
And if I have a GridView that has a child template and this child template has another child template inside. How can I know if the event click is in the Master, the child or the child inside?
 
Kind regards,
0
Alexander
Telerik team
answered on 22 Sep 2010, 02:02 PM
Hello Fernando,

You can use the following recursive method to define the level of hierarchy of each GridViewTemplate:
private void radGridView1_CellClick(object sender, GridViewCellEventArgs e)
{
    int templateLevel = 0;
    GridViewTemplate parentTemplate = e.Row.ViewTemplate.Parent;
    while (parentTemplate != null)
    {
        templateLevel++;
        parentTemplate = parentTemplate.Parent;
    }
 
    // templateLevel = 0 -> MasterTemplate
    // templateLevel = 1 -> ChildTemplate of the MasterTemplate
    // templateLevel = 2 -> ChildTemplate of the first level ChildTemplate
    // ...
}

I hope it helps.

Best regards,
Alexander
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Eddie Harvey
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Fernando Moragrega
Top achievements
Rank 1
Share this question
or