-
C#教程之DevExpress之TreeList用法实例总结
本文实例总结了DevExpress之TreeList用法,希望对大家学习C#程序设计起到一定的帮助作用。具体实例如下:
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
|
using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; using DevExpress.XtraBars; using DevExpress.XtraTreeList; using DevExpress.XtraTreeList.Nodes; namespace DevExpressUtilHelpV3 { public static class TreeListToolV3 { public delegate string BuildPathRule( string nodeText, string fullPathInfo); /// <summary> /// 获取选中节点到根节点的所有信息 /// </summary> /// <param name="focusedNode">TreeListNode</param> /// <param name="columnID">列名称</param> /// <param name="buildPathRule">规则委托</param> /// <returns>路径信息</returns> public static string FullPathInfo( this TreeListNode focusedNode, string columnID, BuildPathRule buildPathRule) { if (focusedNode == null ) throw new ArgumentNullException( "focusedNode" ); if ( string .IsNullOrEmpty( "columnID" )) throw new ArgumentNullException( "columnID" ); string _fullPathInfo = string .Empty; _fullPathInfo = focusedNode.GetDisplayText(columnID); while (focusedNode.ParentNode != null ) { focusedNode = focusedNode.ParentNode; string _nodeText = focusedNode.GetDisplayText(columnID).Trim(); _fullPathInfo = buildPathRule(_nodeText, _fullPathInfo); } return _fullPathInfo; } public delegate bool CompareNodeRule(TreeListNode focusedNode); /// <summary> /// 获取筛选节点到根节点的所有信息 /// </summary> /// <param name="focusedNode">TreeListNode</param> /// <param name="columnID">列名称</param> /// <param name="compareNodeRule">规则委托</param> /// <param name="buildPathRule">规则委托</param> /// <returns>路径信息</returns> public static string FilterPathInfo( this TreeListNode focusedNode, string columnID, CompareNodeRule compareNodeRule, BuildPathRule buildPathRule) { if (focusedNode == null ) throw new ArgumentNullException( "focusedNode" ); if ( string .IsNullOrEmpty( "columnID" )) throw new ArgumentNullException( "columnID" ); string _fullPathInfo = string .Empty; _fullPathInfo = focusedNode.GetDisplayText(columnID); while (focusedNode.ParentNode != null ) { focusedNode = focusedNode.ParentNode; if (compareNodeRule(focusedNode)) { string _nodeText = focusedNode.GetDisplayText(columnID).Trim(); _fullPathInfo = buildPathRule(_nodeText, _fullPathInfo); } } return _fullPathInfo; } /// <summary> /// 递归遍历树节点 /// </summary> /// <param name="tree"></param> /// <param name="opreateRule"></param> public static void LoopTree( this TreeList tree, Action<TreeListNode> opreateRule) { if (tree == null ) throw new ArgumentNullException( "tree" ); foreach (TreeListNode node in tree.Nodes) { opreateRule(node); if (node.Nodes.Count > 0) { LoopTreeNodes(node, opreateRule); } } } /// <summary> /// 递归遍历TreeListNode节点 /// </summary> /// <param name="node"></param> /// <param name="opreateRule"></param> public static void LoopTreeNodes( this TreeListNode node, Action<TreeListNode> opreateRule) { if (node == null ) throw new ArgumentNullException( "node" ); foreach (TreeListNode _childNode in node.Nodes) { opreateRule(_childNode); LoopTreeNodes(_childNode, opreateRule); } } /// <summary> /// 递归遍历TreeListNode,当opreateRule返回false停止循环 /// </summary> /// <param name="node">TreeListNode</param> /// <param name="opreateRule">Func<TreeListNode, bool></param> public static void LoopTreeNodes_Break( this TreeListNode node, Func<TreeListNode, bool > opreateRule) { if (node == null ) throw new ArgumentNullException( "node" ); foreach (TreeListNode _childNode in node.Nodes) { if (!opreateRule(_childNode)) break ; LoopTreeNodes_Break(_childNode, opreateRule); } } /// <summary> /// 递归遍历TreeListNode,当opreateRule返回false跳出循环,直接进入下次循环 /// </summary> /// <param name="node">TreeListNode</param> /// <param name="opreateRule">Func<TreeListNode, bool></param> public static void LoopTreeNodes_Continue( this TreeListNode node, Func<TreeListNode, bool > opreateRule) { if (node == null ) throw new ArgumentNullException( "node" ); foreach (TreeListNode _childNode in node.Nodes) { if (!opreateRule(_childNode)) continue ; LoopTreeNodes_Continue(_childNode, opreateRule); } } public delegate bool CheckNodeRule(TreeListNode fucusedNode); public delegate void CheckNodeNullRule(); /// <summary> /// 节点为null检查 /// </summary> /// <param name="fucusedNode">TreeListNode</param> /// <param name="checkNodeRule">若为NULL,处理逻辑</param> /// <returns>TreeListNode</returns> public static TreeListNode CheckNull( this TreeListNode fucusedNode, CheckNodeNullRule checkNodeRule) { if (fucusedNode == null ) { checkNodeRule(); return null ; } return fucusedNode; } /// <summary> /// 正对节点的检查逻辑 /// </summary> /// <param name="fucusedNode">TreeListNode</param> /// <param name="checkNodeRule">检查逻辑代码[委托]</param> /// <returns>TreeListNode</returns> public static TreeListNode Check( this TreeListNode fucusedNode, CheckNodeRule checkNodeRule) { if (fucusedNode != null ) return checkNodeRule(fucusedNode) == true ? fucusedNode : null ; return null ; } /// <summary> /// 水平滚动条 /// </summary> /// <param name="tree">TreeList</param> public static void HorzScroll( this TreeList tree) { if (tree == null ) throw new ArgumentNullException( "tree" ); tree.OptionsView.AutoWidth = false ; tree.BestFitColumns(); tree.HorzScrollVisibility = ScrollVisibility.Always; } /// <summary> /// 为TreeList附加右键菜单 /// MouseUp(object sender, MouseEventArgs e)事件中调用 /// </summary> /// <param name="tree">TreeList</param> /// <param name="e">MouseEventArgs</param> /// <param name="menu">PopupMenu</param> /// <param name="attachMenuRule">AttachMenuRule</param> public static void AttachMenu( this TreeList tree, MouseEventArgs e, PopupMenu menu, Func<TreeListNode, bool > attachMenuRule) { if (tree == null ) throw new ArgumentNullException( "tree" ); if (menu == null ) throw new ArgumentNullException( "menu" ); if (e.Button == MouseButtons.Right && Control.ModifierKeys == Keys.None && tree.State == TreeListState.Regular) { Point _point = new Point(Cursor.Position.X, Cursor.Position.Y); TreeListHitInfo _hitInfo = tree.CalcHitInfo(e.Location); if (_hitInfo.HitInfoType == HitInfoType.Cell) tree.SetFocusedNode(_hitInfo.Node); if (attachMenuRule(tree.FocusedNode)) menu.ShowPopup(_point); } } /// <summary> /// 设置父节点的状态AfterCheckNode(object sender, NodeEventArgs e) /// </summary> /// <param name="node"></param> /// <param name="check"></param> public static void ProcessNodeCheckState( this TreeListNode node, CheckState check) { if (node == null ) throw new ArgumentNullException( "node" ); SetCheckedChildNodes(node, check); SetCheckedParentNodes(node, check); } /// <summary> /// 设置子节点CheckState /// </summary> /// <param name="node"></param> /// <param name="check"></param> private static void SetCheckedChildNodes(TreeListNode node, CheckState check) { if (node != null ) { node.LoopTreeNodes((TreeListNode _node) => { _node.CheckState = check; }); } } /// <summary> /// 设置父节点CheckState /// </summary> /// <param name="node"></param> /// <param name="check"></param> private static void SetCheckedParentNodes(TreeListNode node, CheckState check) { if (node.ParentNode != null ) { bool _checkStatus = false ; CheckState _nodeState; node.LoopTreeNodes_Break((TreeListNode _node) => { _nodeState = _node.CheckState; if (!check.Equals(_nodeState)) { _checkStatus = !_checkStatus; return false ; //跳出循环 } return true ; //继续循环 }); node.ParentNode.CheckState = _checkStatus ? CheckState.Indeterminate : check; SetCheckedParentNodes(node.ParentNode, check); } } /// <summary> /// 根据CheckState获取TreeListNode /// </summary> /// <param name="tree">TreeList</param> /// <param name="state">CheckState</param> /// <param name="GetNodesByStateRule">返回True的时候继续</param> /// <returns>TreeListNode集合</returns> public static List<TreeListNode> GetNodesByState( this TreeList tree, CheckState state, Func<TreeListNode, bool > GetNodesByStateRule) { if (tree == null ) throw new ArgumentNullException( "tree" ); List<TreeListNode> _checkNodes = new List<TreeListNode>(); tree.LoopTree((TreeListNode node) => { if (GetNodesByStateRule(node)) { if (node.CheckState == state) _checkNodes.Add(node); } }); return _checkNodes; } } } |
本文实例备有详尽的注释,可以帮助大家更好的加以理解。
栏目列表
最新更新
nodejs爬虫
Python正则表达式完全指南
爬取豆瓣Top250图书数据
shp 地图文件批量添加字段
爬虫小试牛刀(爬取学校通知公告)
【python基础】函数-初识函数
【python基础】函数-返回值
HTTP请求:requests模块基础使用必知必会
Python初学者友好丨详解参数传递类型
如何有效管理爬虫流量?
SQL SERVER中递归
2个场景实例讲解GaussDB(DWS)基表统计信息估
常用的 SQL Server 关键字及其含义
动手分析SQL Server中的事务中使用的锁
openGauss内核分析:SQL by pass & 经典执行
一招教你如何高效批量导入与更新数据
天天写SQL,这些神奇的特性你知道吗?
openGauss内核分析:执行计划生成
[IM002]Navicat ODBC驱动器管理器 未发现数据
初入Sql Server 之 存储过程的简单使用
这是目前我见过最好的跨域解决方案!
减少回流与重绘
减少回流与重绘
如何使用KrpanoToolJS在浏览器切图
performance.now() 与 Date.now() 对比
一款纯 JS 实现的轻量化图片编辑器
关于开发 VS Code 插件遇到的 workbench.scm.
前端设计模式——观察者模式
前端设计模式——中介者模式
创建型-原型模式