当前位置:网站首页>Summary of common usage of dev treelist
Summary of common usage of dev treelist
2022-07-26 06:37:00 【51CTO】
author :jiankunking
Requirements are as follows :
1: After selecting the parent node , Check all child nodes ;
2: Select the child node instead of the parent node , From the parent node of the current node to the root node check The boxes are all half selected .
3: When none of the child nodes is checked , Set the parent node status to : Unchecked state
The specific implementation is as follows :
One 、OptionView—ShowCheckBoxes The attribute is true, Then one... Is automatically added in front of each node check box .
Two 、 Set up OptionBehavior—AllIndeterminateCheckState The attribute is true, be check The box can be half selected .
The specific code is shown below :
#region
Tree form
Before clicking the node
/// <summary>
/// Before clicking the node
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private
void
treeList_BeforeCheckNode(
object
sender,
CheckNodeEventArgs
e)
{
if (
!
this.
ifMultipleChoice)
{
// Cancel the previously selected , Realize radio function
List
<
DevExpress.
XtraTreeList.
Nodes.
TreeListNode
>
treeListNodes
=
treeList.
GetAllCheckedNodes();
foreach (
DevExpress.
XtraTreeList.
Nodes.
TreeListNode
node
in
treeListNodes)
{
node.
Checked
=
false;
}
}
e.
State
= (
e.
PrevState
==
CheckState.
Checked
?
CheckState.
Unchecked :
CheckState.
Checked);
}
#endregion
#region
Tree form
Click the node
/// <summary>
/// Click the node
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private
void
treeList_AfterCheckNode(
object
sender,
NodeEventArgs
e)
{
if (
!
this.
ifMultipleChoice)
{
return;
}
if (
e.
Node
==
null)
{
return;
}
if (
e.
Node.
CheckState
==
CheckState.
Indeterminate)
{
e.
Node.
CheckState
=
CheckState.
Checked;
}
if (
e.
Node.
CheckState
==
CheckState.
Checked)
{
if (
e.
Node.
HasChildren)
{
this.
CheckNode(
e.
Node);
}
this.
ValidParentIsChecked(
e.
Node);
}
else
if (
e.
Node.
CheckState
==
CheckState.
Unchecked)
{
if (
e.
Node.
HasChildren)
{
this.
SetCheckedChildNodes(
e.
Node,
CheckState.
Unchecked);
}
// From the root node down Inquire about Whether there is a checked child node , If so Parent node The semi selected state remains unchanged Otherwise it becomes Don't choose the State
//this.ValidParentNodeIsCanleSel(e.Node);
SetCheckedParentNodes(
e.
Node,
e.
Node.
CheckState);
}
}
#endregion
#region
Tree form
Node operation set
/// <summary>
/// Select a node and its children
/// </summary>
/// <param name="node"></param>
private
void
CheckNode(
DevExpress.
XtraTreeList.
Nodes.
TreeListNode
node)
{
foreach (
DevExpress.
XtraTreeList.
Nodes.
TreeListNode
cnode
in
node.
Nodes)
{
if (
cnode
!=
null)
{
cnode.
CheckState
=
CheckState.
Checked;
}
if (
cnode.
HasChildren)
{
CheckNode(
cnode);
}
}
}
/// <summary>
/// Check the child node , Modify the state of the parent node
/// </summary>
/// <param name="node"></param>
private
void
ValidParentIsChecked(
DevExpress.
XtraTreeList.
Nodes.
TreeListNode
node)
{
if (
node.
ParentNode
!=
null)
{
// The parent node is not selected
if (
node.
ParentNode.
CheckState
==
CheckState.
Unchecked)
{
// This node has child nodes also This node and child nodes are selected
if (
node.
HasChildren
&&
ValidIsCheckAllChildNode(
node.
ParentNode))
{
node.
ParentNode.
CheckState
=
CheckState.
Checked;
}
// The node has no children also The child nodes under its parent node are selected
else
if ((
!
node.
HasChildren)
&&
ValidIsCheckAllChildNode(
node.
ParentNode))
{
node.
ParentNode.
CheckState
=
CheckState.
Checked;
}
else
{
node.
ParentNode.
CheckState
=
CheckState.
Indeterminate;
}
}
else
if (
node.
ParentNode.
CheckState
==
CheckState.
Indeterminate)
{
// This node has child nodes and When none of the child nodes is selected , Modify its state
if (
node.
HasChildren
&& (
!
this.
ValidIsHasCheckChildNode(
node)))
{
node.
ParentNode.
CheckState
=
CheckState.
Unchecked;
}
// All nodes under the parent node of this node are selected ValidIsCheckAllChildNode
else
if (
ValidIsCheckAllChildNode(
node.
ParentNode))
{
node.
ParentNode.
CheckState
=
CheckState.
Checked;
}
}
this.
ValidParentIsChecked(
node.
ParentNode);
}
}
/// <summary>
/// From this node down Inquire about Whether there is a checked child node , If so Parent node Semi selective 、 The selected state remains unchanged, otherwise it changes to Don't choose the State
/// </summary>
/// <param name="node"></param>
private
void
ValidParentNodeIsCanleSel(
DevExpress.
XtraTreeList.
Nodes.
TreeListNode
node)
{
bool
isSel
=
false;
if (
node.
ParentNode
!=
null)
{
if (
node.
ParentNode.
CheckState
==
CheckState.
Indeterminate)
{
// If the parent node's Status as Semi selective state this According to the parent node Judge whether the child node is checked
isSel
=
ValidIsHasCheckChildNode(
node.
ParentNode);
if (
isSel
==
false)
{
// If all Child node None “ Choose ” that The state of the parent node Turn into Unselected
node.
ParentNode.
CheckState
=
CheckState.
Unchecked;
}
}
this.
ValidParentNodeIsCanleSel(
node.
ParentNode);
}
}
/// <summary>
/// Judge whether there is a node selected under this node , If there is a return true
/// </summary>
/// <param name="node"></param>
/// <returns></returns>
private
bool
ValidIsHasCheckChildNode(
DevExpress.
XtraTreeList.
Nodes.
TreeListNode
node)
{
bool
isCheck
=
false;
foreach (
DevExpress.
XtraTreeList.
Nodes.
TreeListNode
cnode
in
node.
Nodes)
{
if (
cnode
!=
null)
{
if (
cnode.
CheckState
==
CheckState.
Checked)
{
isCheck
=
true;
return
isCheck;
}
}
if (
cnode.
HasChildren)
{
isCheck
=
this.
ValidIsHasCheckChildNode(
cnode);
if (
isCheck
==
true)
{
return
isCheck;
}
}
}
return
isCheck;
}
/// <summary>
/// Select all nodes
/// </summary>
/// <param name="node"></param>
/// <returns></returns>
private
bool
ValidIsCheckAllChildNode(
DevExpress.
XtraTreeList.
Nodes.
TreeListNode
node)
{
bool
isCheck
=
true;
foreach (
DevExpress.
XtraTreeList.
Nodes.
TreeListNode
cnode
in
node.
Nodes)
{
if (
cnode
!=
null)
{
if (
cnode.
CheckState
==
CheckState.
Unchecked)
{
isCheck
=
false;
return
isCheck;
}
}
if (
cnode.
HasChildren)
{
isCheck
=
this.
ValidIsCheckAllChildNode(
cnode);
if (
isCheck
==
false)
{
return
isCheck;
}
}
}
return
isCheck;
}
#endregion
#region
Tree form
Get all child nodes
private
void
GetChildNodes(
TreeListNode
parentNode,
List
<
TreeListNode
>
list)
{
if (
parentNode
==
null)
{
return;
}
if (
parentNode.
Nodes.
Count
>
0)
{
foreach (
TreeListNode
node
in
parentNode.
Nodes)
{
list.
Add(
node);
if (
node.
Nodes.
Count
>
0)
{
GetChildNodes(
node,
list);
}
}
}
}
#endregion
#region
Tree form
Triggered when a child node is selected
/// <summary>
/// Triggered when a child node is selected
/// </summary>
/// <param name="node"></param>
/// <param name="check"></param>
private
void
SetCheckedChildNodes(
TreeListNode
node,
CheckState
check)
{
foreach (
TreeListNode
tn
in
node.
Nodes)
{
tn.
CheckState
=
check;
if (
tn.
HasChildren)
{
SetCheckedChildNodes(
tn,
check);
}
}
}
#endregion
#region
Tree form
Triggered when the parent node is selected
/// <summary>
/// Triggered when the parent node is selected
/// </summary>
/// <param name="node"></param>
/// <param name="check"></param>
private
void
SetCheckedParentNodes(
TreeListNode
node,
CheckState
check)
{
if (
node.
ParentNode
!=
null)
{
bool
b
=
false;
CheckState
state;
foreach (
TreeListNode
tln
in
node.
ParentNode.
Nodes)
{
state
= (
CheckState)
tln.
CheckState;
if (
!
check.
Equals(
state))
{
b
=
!
b;
break;
}
}
node.
ParentNode.
CheckState
=
b
?
CheckState.
Indeterminate :
check;
SetCheckedParentNodes(
node.
ParentNode,
check);
}
}
#endregion
#region
Tree form
Judge whether all child nodes under this node are selected
/// <summary>
/// Judge whether all child nodes under this node are selected
/// </summary>
/// <param name="node"></param>
/// <returns></returns>
private
Boolean
IsChildsChecked(
TreeListNode
node)
{
foreach (
TreeListNode
tln
in
node.
ParentNode.
Nodes)
{
if (
tln.
CheckState
==
CheckState.
Unchecked)
{
return
false;
}
if (
tln.
HasChildren)
{
IsChildsChecked(
tln);
}
}
return
true;
}
#endregion
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
- 77.
- 78.
- 79.
- 80.
- 81.
- 82.
- 83.
- 84.
- 85.
- 86.
- 87.
- 88.
- 89.
- 90.
- 91.
- 92.
- 93.
- 94.
- 95.
- 96.
- 97.
- 98.
- 99.
- 100.
- 101.
- 102.
- 103.
- 104.
- 105.
- 106.
- 107.
- 108.
- 109.
- 110.
- 111.
- 112.
- 113.
- 114.
- 115.
- 116.
- 117.
- 118.
- 119.
- 120.
- 121.
- 122.
- 123.
- 124.
- 125.
- 126.
- 127.
- 128.
- 129.
- 130.
- 131.
- 132.
- 133.
- 134.
- 135.
- 136.
- 137.
- 138.
- 139.
- 140.
- 141.
- 142.
- 143.
- 144.
- 145.
- 146.
- 147.
- 148.
- 149.
- 150.
- 151.
- 152.
- 153.
- 154.
- 155.
- 156.
- 157.
- 158.
- 159.
- 160.
- 161.
- 162.
- 163.
- 164.
- 165.
- 166.
- 167.
- 168.
- 169.
- 170.
- 171.
- 172.
- 173.
- 174.
- 175.
- 176.
- 177.
- 178.
- 179.
- 180.
- 181.
- 182.
- 183.
- 184.
- 185.
- 186.
- 187.
- 188.
- 189.
- 190.
- 191.
- 192.
- 193.
- 194.
- 195.
- 196.
- 197.
- 198.
- 199.
- 200.
- 201.
- 202.
- 203.
- 204.
- 205.
- 206.
- 207.
- 208.
- 209.
- 210.
- 211.
- 212.
- 213.
- 214.
- 215.
- 216.
- 217.
- 218.
- 219.
- 220.
- 221.
- 222.
- 223.
- 224.
- 225.
- 226.
- 227.
- 228.
- 229.
- 230.
- 231.
- 232.
- 233.
- 234.
- 235.
- 236.
- 237.
- 238.
- 239.
- 240.
- 241.
- 242.
- 243.
- 244.
- 245.
- 246.
- 247.
- 248.
- 249.
- 250.
- 251.
- 252.
- 253.
- 254.
- 255.
- 256.
- 257.
- 258.
- 259.
- 260.
- 261.
- 262.
- 263.
- 264.
- 265.
- 266.
- 267.
- 268.
- 269.
- 270.
- 271.
- 272.
- 273.
- 274.
- 275.
- 276.
- 277.
- 278.
- 279.
- 280.
- 281.
- 282.
- 283.
- 284.
- 285.
- 286.
- 287.
- 288.
- 289.
- 290.
- 291.
- 292.
- 293.
- 294.
- 295.
- 296.
- 297.
- 298.
- 299.
- 300.
The above code reference : Click to open the link
边栏推荐
猜你喜欢

多目标检测

将一个正整数分解质因数,要求分解成尽可能小的多个的因数。

TCP protocol -- message format, connection establishment, reliable transmission, congestion control

输入5个学生的记录(每条记录包括学号和成绩), 组成记录数组, 然后按照成绩由高到低的次序输出. 排序方法采用选择排序

Yolov6: the fast and accurate target detection framework is open source

『HarmonyOS』探索HarmonyOS应用
![[day_060423] no two](/img/2b/5bcb3e089a3157fe72a50ddb767e63.png)
[day_060423] no two

少儿编程 电子学会图形化编程等级考试Scratch一级真题解析(选择题)2022年6月

Vision Transformer 必读系列之图像分类综述

Jz36 binary search tree and bidirectional linked list
随机推荐
『牛客|每日一题』点击消除
【pytorch】图片增广
Interpretation of TPS motion (cvpr2022) video generation paper
[untitled]
[day_020419] inverted string
@ConstructorProperties注解理解以及其对应使用方式
IP day 10 notes - BGP
【C语言】文件操作
Upgrade appium automation framework to the latest 2.0
Design principle of infrared circuit of single chip microcomputer
[1] Basic knowledge of mathematical modeling
How can machinery manufacturing enterprises do well in production management with the help of ERP system?
JS date details, string to date
带你搞透IO多路复用原理(select、poll和epoll)
Address resolution ARP Protocol
BPG notes (IV)
【图像去噪】基于双立方插值和稀疏表示实现图像去噪matlab源码
【图像隐藏】基于混合 DWT-HD-SVD 的数字图像水印方法技术附matlab代码
[day_050422] continuous maximum sum
The real epidemic situation in the United States, do not easily "bottom" 2020-03-23