To display the check box before the node, you must modify the attribute OptionsView-> ShowCheckBoxes = True.
The rules for the subnode and parent node of the check box are as follows:
1. When a node is selected, all the child nodes of the node are selected
2. When a node is canceled, all child nodes of the node are deselected.
3. When all the subnodes of a node are selected
4. if not all subnodes of a node are selected, this node is not selected
Private void treelistappsafterchecknode (object sender, NodeEventArgs e ){
SetCheckedChildNodes (e. Node, e. Node. CheckState );
SetCheckedParentNodes (e. Node, e. Node. CheckState );
}
Private void treelistinclubeforechecknode (object sender, CheckNodeEventArgs e ){
E. State = (e. PrevState = CheckState. Checked? CheckState. Unchecked: CheckState. Checked );
}
Private void SetCheckedChildNodes (TreeListNode node, CheckState check ){
For (int I = 0; I <node. Nodes. Count; I ++ ){
Node. Nodes [I]. CheckState = check;
SetCheckedChildNodes (node. Nodes [I], check );
}
}
Private void SetCheckedParentNodes (TreeListNode node, CheckState check ){
If (node. ParentNode! = Null ){
Bool B = false;
CheckState state;
For (int I = 0; I <node. ParentNode. Nodes. Count; I ++ ){
State = (CheckState) node. ParentNode. Nodes [I]. CheckState;
If (! Check. Equals (state )){
B =! B;
Break;
}
}
Node. ParentNode. CheckState = B? CheckState. Indeterminate: check;
SetCheckedParentNodes (node. ParentNode, check );
}
}
Private void GetCheckedID (TreeListNode parentNode)
{
If (parentNode. Nodes. Count = 0)
{
Return; // recursively terminate www.2cto.com
}
Foreach (TreeListNode node in parentNode. Nodes)
{
If (node. CheckState = CheckState. Checked)
{
DataRowView drv = treeList1.GetDataRecordByNode (node) as DataRowView; // key code
If (drv! = Null)
{
Int GroupID = (int) drv ["GroupID"];
LstCheckedOfficeID. Add (GroupID );
}
Private void btnOK_Click (object sender, EventArgs e)
{
This. lstCheckedOfficeID. Clear ();
If (treeList1.Nodes. Count> 0)
{
Foreach (TreeListNode root in treeList1.Nodes)
{
GetCheckedOfficeID (root );
}
}
String idStr = string. Empty;
Foreach (int id in lstCheckedOfficeID)
{
IdStr + = id + "";
}
}
}
GetCheckedOfficeID (node );
}
}
From SYZ_YUMEIZHOU_YY