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

Find GridControl for child grid

3 Answers 105 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 19 Jun 2017, 08:39 PM
We are using an unbound hierarchical RadGridView. 

When there is a MouseDown click event on a cell in a child grid, how can we find out which GridControl the cell belongs to?

3 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 20 Jun 2017, 07:48 AM
Hi Jeff,

Thank you for writing.

Please note that you can use the CellClick event as well. The following snippet shows how you can check the template with both events:
private void RadGridView1_MouseDown(object sender, MouseEventArgs e)
{
    var cell = radGridView1.ElementTree.GetElementAtPoint(e.Location) as GridDataCellElement;
    if (cell != null)
    {
        if (cell.RowInfo.ViewTemplate == radGridView1.MasterTemplate)
        {
            Console.WriteLine("MasteTempalte");
        }
        else
        {
            Console.WriteLine("ChildTempalte");
 
        }
    }
}
 
private void RadGridView1_CellClick(object sender, GridViewCellEventArgs e)
{
    if (e.Row.ViewTemplate == radGridView1.MasterTemplate)
    {
        Console.WriteLine("MasteTempalte");
    }
    else
    {
        Console.WriteLine("ChildTempalte");
 
    }
}
 
Please let me know if there is something else I can help you with. 
 
Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Jeff
Top achievements
Rank 1
answered on 20 Jun 2017, 09:49 AM

We have multiple child grids (4 different levels). We need to know the GridControl pointer. MasterTemplate and ChildTemplate is not enough.

We need to get childtemplate cells header and values.

 

0
Dimitar
Telerik team
answered on 20 Jun 2017, 11:54 AM
Hello Jeff,

I am not sure what you mean by saying GridControl pointer. You can get the parent control of any element like this:
var grid = cell.ElementTree.Control;

In general, the ViewTemplate will contain the columns names, the rows, and all the information about the current child grid:
private void RadGridView1_MouseDown(object sender, MouseEventArgs e)
{
    var cell = radGridView1.ElementTree.GetElementAtPoint(e.Location) as GridDataCellElement;
    if (cell != null)
    {
        foreach (var item in cell.RowInfo.ViewTemplate.Columns)
        {
            Console.WriteLine(item.Name);
        }     
    }
}

Let me know if you have additional questions.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
GridView
Asked by
Jeff
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Jeff
Top achievements
Rank 1
Share this question
or