Search code examples
c#telerik-gridradgridradgridview

RadGridView get child template data?


I am trying to get just the data for a child template when iterating through a grid.

I start with this:

        foreach (GridViewRowInfo row in radGridView1.Rows)
        {
            err = IterateChildRows(row);
        }

and pass the row to this:

    private bool IterateChildRows(GridViewRowInfo rowInfo)
    {
        bool err = false;
        if (rowInfo.Cells[5].Value != null && rowInfo.Cells[5].Value.ToString() != "01/01/1900")
        {
            if (rowInfo.Cells[0].ViewTemplate.Templates[0].Caption == "Current")
            {
                if (rowInfo.ViewTemplate.Templates[0].RowCount == 0)
                {
                    MessageBox.Show("Not all products have CURRENT quantity breaks", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    err = true;
                }
            }
        }
        return err;
     }

My problem is I can't seem to find just the child template data for the row I passed in. Everything I have tried seems to have ALL the child rows from all the master template items and not just the row I passed in.

So if I have 2 items in my main grid and 3 items each in my child template then I get a count of 6 and not 3.

I don't know where I am going wrong...

Anyone?

Cheers Dean


Solution

  • Try the following, the childrows are accessible through HierarchyRowInfo

    private bool IterateChildRows(GridViewRowInfo rowInfo)
    {
        bool err = false;
        GridViewHierarchyRowInfo hierarchyRow = rowInfo as GridViewHierarchyRowInfo;
    
        //To get current row childRows count
        int noOfChildRows = hierarchyRow.ChildRows.Count;
    
        //looping through the child rows
        foreach (GridViewRowInfo row in hierarchyRow.ChildRows)
        {   
            //check if its current child row
            if(row.IsCurrent)
            {
               // Do your logic
            }
        }
    
        return err;
     }