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

Check/uncheck all checkboxes of childstemplates

1 Answer 52 Views
GridView
This is a migrated thread and some comments may be shown as answers.
gerbrand
Top achievements
Rank 2
gerbrand asked on 08 Apr 2009, 01:44 PM
Hello,

Okay I've got a gridview that has 2 levels: parent, child. 
Now in both levels I've got a checkbox column.
So I want to check/uncheck all checkboxes in the child level when I clicked on the parent his checkbox.

I got it working I thought but I'm getting some strange behavior. I think I know why, but I have no idea for the moment how to solve it.

okay my code snippet:

private void rgvAdserverNetwork_ValueChanged(object sender, EventArgs e) 
    var cell = sender as GridDataCellElement; 
    if (cell == null || ((GridViewDataColumn)cell.ColumnInfo).FieldName != "Add"return
     
    var viewTemp = cell.ViewTemplate; 
    var tempRow = cell.RowElement; 
    var rowinfo = tempRow.RowInfo; 
     
    if (!(bool)cell.Value) 
    { 
        //loop the child items to set the checkbox to true 
        loopChilds(rowinfo);   
        rowinfo.Cells["Add"].Value = true//set the checkbox of the parent to true 
    } 
 
//loop the child items of the given master row 
private void loopChilds(GridViewRowInfo masterrow) 
    var childRows = masterrow.ViewTemplate.ChildGridViewTemplates[0].GetChildRows(masterrow); 
    if (childRows == nullreturn
    var length = childRows.Length; 
 
    var expandedState = masterrow.IsExpanded; 
    masterrow.IsExpanded = true
 
    for (var i = 0; i < length; i++) 
    { 
        childRows[i].Cells["Add"].Value = true//set the checkbox of the parent to true 
    } 
    masterrow.IsExpanded = expandedState; 

Maybe there is a better way to achieve this.

Thanks a lot in advanced.

1 Answer, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 10 Apr 2009, 02:05 PM
Hi Gerbrand,

I tested the code and found that exception is fired when you try to check whether a row is not expanded. We located the issue and it will be addressed in the upcoming service pack.

Could you please specify this strange behavior and we will try to find a solution.

Sincerely yours,
Jack
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
gerbrand
Top achievements
Rank 2
Answers by
Jack
Telerik team
Share this question
or