This article summarizes the usage of TreeList in DevExpress, hoping to help everyone learn C# programming. Specific examples are as follows:
using System; using ; using ; using ; using ; using ; using ; namespace DevExpressUtilHelpV3 { public static class TreeListToolV3 { public delegate string BuildPathRule(string nodeText, string fullPathInfo); /// <summary> /// Get all information from the selected node to the root node /// </summary> /// <param name="focusedNode">TreeListNode</param> /// <param name="columnID">Column name</param> /// <param name="buildPathRule">Rules delegation</param> /// <returns>Path information</returns> public static string FullPathInfo(this TreeListNode focusedNode, string columnID, BuildPathRule buildPathRule) { if (focusedNode == null) throw new ArgumentNullException("focusedNode"); if (("columnID")) throw new ArgumentNullException("columnID"); string _fullPathInfo = ; _fullPathInfo = (columnID); while ( != null) { focusedNode = ; string _nodeText = (columnID).Trim(); _fullPathInfo = buildPathRule(_nodeText, _fullPathInfo); } return _fullPathInfo; } public delegate bool CompareNodeRule(TreeListNode focusedNode); /// <summary> /// Get all information from filtering nodes to root nodes /// </summary> /// <param name="focusedNode">TreeListNode</param> /// <param name="columnID">Column name</param> /// <param name="compareNodeRule">Rules delegation</param> /// <param name="buildPathRule">Rules delegation</param> /// <returns>Path information</returns> public static string FilterPathInfo(this TreeListNode focusedNode, string columnID, CompareNodeRule compareNodeRule, BuildPathRule buildPathRule) { if (focusedNode == null) throw new ArgumentNullException("focusedNode"); if (("columnID")) throw new ArgumentNullException("columnID"); string _fullPathInfo = ; _fullPathInfo = (columnID); while ( != null) { focusedNode = ; if (compareNodeRule(focusedNode)) { string _nodeText = (columnID).Trim(); _fullPathInfo = buildPathRule(_nodeText, _fullPathInfo); } } return _fullPathInfo; } /// <summary> /// Recursively traverse tree nodes /// </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 ) { opreateRule(node); if ( > 0) { LoopTreeNodes(node, opreateRule); } } } /// <summary> /// Recursively traverse TreeListNode node /// </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 ) { opreateRule(_childNode); LoopTreeNodes(_childNode, opreateRule); } } /// <summary> /// Recursively traverse TreeListNode, stop looping when preventRule returns 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 ) { if (!opreateRule(_childNode)) break; LoopTreeNodes_Break(_childNode, opreateRule); } } /// <summary> /// Recursively traverse TreeListNode, when preventRule returns false, jump out of the loop, directly enter the next loop /// </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 ) { if (!opreateRule(_childNode)) continue; LoopTreeNodes_Continue(_childNode, opreateRule); } } public delegate bool CheckNodeRule(TreeListNode fucusedNode); public delegate void CheckNodeNullRule(); /// <summary> /// Check the node for null /// </summary> /// <param name="fucusedNode">TreeListNode</param> /// <param name="checkNodeRule">If it is NULL, processing logic</param> /// <returns>TreeListNode</returns> public static TreeListNode CheckNull(this TreeListNode fucusedNode, CheckNodeNullRule checkNodeRule) { if (fucusedNode == null) { checkNodeRule(); return null; } return fucusedNode; } /// <summary> /// Check logic for node /// </summary> /// <param name="fucusedNode">TreeListNode</param> /// <param name="checkNodeRule">Check logic code [delegation]</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> /// Horizontal scroll bar /// </summary> /// <param name="tree">TreeList</param> public static void HorzScroll(this TreeList tree) { if (tree == null) throw new ArgumentNullException("tree"); = false; (); = ; } /// <summary> ///Add a right-click menu to TreeList /// Called in MouseUp(object sender, MouseEventArgs e) event /// </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 ( == && == && == ) { Point _point = new Point(, ); TreeListHitInfo _hitInfo = (); if (_hitInfo.HitInfoType == ) (_hitInfo.Node); if (attachMenuRule()) (_point); } } /// <summary> /// Set the status of the parent node 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> /// Set child node CheckState /// </summary> /// <param name="node"></param> /// <param name="check"></param> private static void SetCheckedChildNodes(TreeListNode node, CheckState check) { if (node != null) { ((TreeListNode _node) => { _node.CheckState = check; }); } } /// <summary> /// Set parent node CheckState /// </summary> /// <param name="node"></param> /// <param name="check"></param> private static void SetCheckedParentNodes(TreeListNode node, CheckState check) { if ( != null) { bool _checkStatus = false; CheckState _nodeState; node.LoopTreeNodes_Break((TreeListNode _node) => { _nodeState = _node.CheckState; if (!(_nodeState)) { _checkStatus = !_checkStatus; return false;//Breaking out of the loop } return true;//Continue the loop }); = _checkStatus ? : check; SetCheckedParentNodes(, check); } } /// <summary> /// Get TreeListNode according to CheckState /// </summary> /// <param name="tree">TreeList</param> /// <param name="state">CheckState</param> /// <param name="GetNodesByStateRule">Continue when returning to True</param> /// <returns>TreeListNode collection</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>(); ((TreeListNode node) => { if (GetNodesByStateRule(node)) { if ( == state) _checkNodes.Add(node); } }); return _checkNodes; } } }
The examples in this article are detailed and detailed notes that can help you better understand.