DevExpress之TreeList用法實(shí)例總結(jié)
本文實(shí)例總結(jié)了DevExpress之TreeList用法,希望對(duì)大家學(xué)習(xí)C#程序設(shè)計(jì)起到一定的幫助作用。具體實(shí)例如下:
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> /// 獲取選中節(jié)點(diǎn)到根節(jié)點(diǎn)的所有信息 /// </summary> /// <param name="focusedNode">TreeListNode</param> /// <param name="columnID">列名稱</param> /// <param name="buildPathRule">規(guī)則委托</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> /// 獲取篩選節(jié)點(diǎn)到根節(jié)點(diǎn)的所有信息 /// </summary> /// <param name="focusedNode">TreeListNode</param> /// <param name="columnID">列名稱</param> /// <param name="compareNodeRule">規(guī)則委托</param> /// <param name="buildPathRule">規(guī)則委托</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> /// 遞歸遍歷樹節(jié)點(diǎn) /// </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節(jié)點(diǎn) /// </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,當(dāng)opreateRule返回false停止循環(huán) /// </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,當(dāng)opreateRule返回false跳出循環(huán),直接進(jìn)入下次循環(huán) /// </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> /// 節(jié)點(diǎn)為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> /// 正對(duì)節(jié)點(diǎn)的檢查邏輯 /// </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> /// 水平滾動(dòng)條 /// </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)事件中調(diào)用 /// </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> /// 設(shè)置父節(jié)點(diǎn)的狀態(tài)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> /// 設(shè)置子節(jié)點(diǎn)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> /// 設(shè)置父節(jié)點(diǎn)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;//跳出循環(huán) } return true;//繼續(xù)循環(huán) }); node.ParentNode.CheckState = _checkStatus ? CheckState.Indeterminate : check; SetCheckedParentNodes(node.ParentNode, check); } } /// <summary> /// 根據(jù)CheckState獲取TreeListNode /// </summary> /// <param name="tree">TreeList</param> /// <param name="state">CheckState</param> /// <param name="GetNodesByStateRule">返回True的時(shí)候繼續(xù)</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; } } }
本文實(shí)例備有詳盡的注釋,可以幫助大家更好的加以理解。
- DevExpress之ChartControl用法實(shí)例總結(jié)
- DevExpress SplitContainerControl用法總結(jié)
- DevExpress之ChartControl實(shí)現(xiàn)時(shí)間軸實(shí)例
- DevExpress之ChartControl實(shí)現(xiàn)餅狀圖百分比演示實(shí)例
- C#實(shí)現(xiàn)DevExpress本地化實(shí)例詳解
- DevExpress實(shí)現(xiàn)GridControl單元格編輯驗(yàn)證的方法
- C#實(shí)現(xiàn)WinForm禁止最大化、最小化、雙擊標(biāo)題欄、雙擊圖標(biāo)等操作的方法
- Winform開發(fā)框架中如何使用DevExpress的內(nèi)置圖標(biāo)資源
相關(guān)文章
C#實(shí)現(xiàn)的文件操作封裝類完整實(shí)例【刪除,移動(dòng),復(fù)制,重命名】
這篇文章主要介紹了C#實(shí)現(xiàn)的文件操作封裝類,結(jié)合完整實(shí)例形式分析了C#封裝文件的刪除,移動(dòng),復(fù)制,重命名等操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2017-03-03C#中使用FilleStream實(shí)現(xiàn)視頻文件的復(fù)制功能
這篇文章主要介紹了C#中使用FilleStream實(shí)現(xiàn)視頻文件的復(fù)制功能,本文通過實(shí)例代碼給大家介紹的非常想詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-09-09C#中Byte轉(zhuǎn)換相關(guān)的函數(shù)
這篇文章主要介紹了C#中Byte轉(zhuǎn)換相關(guān)的函數(shù)介紹,非常具有參考借鑒價(jià)值,特此分享到腳本之家平臺(tái)供大家學(xué)習(xí)2016-05-05WPF實(shí)現(xiàn)背景燈光隨鼠標(biāo)閃動(dòng)效果
這篇文章主要為大家詳細(xì)介紹了WPF實(shí)現(xiàn)背景燈光隨鼠標(biāo)閃動(dòng)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-08-08淺析C#中數(shù)組,ArrayList與List對(duì)象的區(qū)別
在C#中,當(dāng)我們想要存儲(chǔ)一組對(duì)象的時(shí)候,就會(huì)想到用數(shù)組,ArrayList,List這三個(gè)對(duì)象了。那么這三者到底有什么樣的區(qū)別呢2013-07-07C#中FormsAuthentication用法實(shí)例
這篇文章主要介紹了C#中FormsAuthentication用法實(shí)例,本文直接給出實(shí)現(xiàn)代碼,需要的朋友可以參考下2015-02-02