Skip to main content Skip to footer

Check/Uncheck All Child Nodes by Checking/Unchecking Root Node in TreeView FlexGrid

Extending FlexGrid functionality we can add a feature which enables us to check/uncheck child nodes when the root/parent node is checked/unchecked. Handle the CellChecked event of C1Flexgrid. The e.Row property would return the node being checked. We will get the count of children for this node using _flex.Rows[e.Row].Node.Children. If the number of children is greater than zero, we will create an object of CellRange which will store the CellRange of this tree node. The firstrow of this range would be the CellRange.r1 and the lastrow would be CellRange.r2 property. Now we will traverse through this cellrange from the first row to the last row and based on the checked state of e.Row, we will check the nodes in this cell range.

private void _flex_CellChecked(object sender, RowColEventArgs e)  
{  
    int children = _flex.Rows[e.Row].Node.Children;  
    int firstRow, lastRow;  

    if (children > 0)  
    {  
        CellRange cr = _flex.Rows[e.Row].Node.GetCellRange();  
        firstRow = cr.r1;  
        lastRow = cr.r2;  

        CheckEnum ck = _flex.GetCellCheck(e.Row, e.Col);  

        for (int i = firstRow; i <= lastRow; i  )  
            _flex.SetCellCheck(i, e.Col, ck);  
    }  
}

WinForms FlexGrid Check or Uncheck all nodes