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 == null) return; |
| 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.