Find GridControl for child grid

4 posts, 0 answers
  1. Jeff
    Jeff avatar
    5 posts
    Member since:
    Sep 2010

    Posted 19 Jun 2017 Link to this post

    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?
  2. Dimitar
    Admin
    Dimitar avatar
    2831 posts

    Posted 20 Jun 2017 Link to this post

    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.
  3. Jeff
    Jeff avatar
    5 posts
    Member since:
    Sep 2010

    Posted 20 Jun 2017 in reply to Dimitar Link to this post

    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.

     

  4. Dimitar
    Admin
    Dimitar avatar
    2831 posts

    Posted 20 Jun 2017 Link to this post

    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.
Back to Top