DevExpress完成禁用TreeListNode CheckBox的辦法。本站提示廣大學習愛好者:(DevExpress完成禁用TreeListNode CheckBox的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是DevExpress完成禁用TreeListNode CheckBox的辦法正文
許多時刻在停止C#項目標現實開辟中,會須要依據前提來設置節點弗成勾選,檢查DevExpress文檔發明經由過程其CustomDrawNodeCheckBox和BeforeCheckNode事宜組合應用可以到達,普通設置節點弗成以勾選的規矩是一樣的,所以對代碼停止略微封裝。本文實例就展現了DevExpress完成禁用TreeListNode CheckBox的辦法。詳細以下:
重要功效代碼以下:
/// <summary> /// 禁用CheckBox /// 解釋 /// 在CustomDrawNodeCheckBox事宜中應用 /// </summary> /// <param name="tree">TreeList</param> /// <param name="conditionHanlder">拜托</param> /// <param name="e">CustomDrawNodeCheckBoxEventArgs</param> public static void DisabledCheckBox(this TreeListNode tree, Predicate<TreeListNode> conditionHanlder, CustomDrawNodeCheckBoxEventArgs e) { if (conditionHanlder(e.Node)) { e.ObjectArgs.State = ObjectState.Disabled; } } /// <summary> /// 制止操作節點CheckBox /// 解釋 /// 在BeforeCheckNode事宜中應用 /// </summary> /// <param name="tree">TreeListNode</param> /// <param name="conditionHanlder">拜托</param> /// <param name="e">CheckNodeEventArgs</param> public static void DisabledSetCheckBox(this TreeListNode tree, Predicate<TreeListNode> conditionHanlder, CheckNodeEventArgs e) { if (conditionHanlder(e.Node)) { e.CanCheck = false; } }
應用示例以下:
/// <summary> /// CustomDrawNodeCheckBox事宜 /// </summary> void LHTree_CustomDrawNodeCheckBox(object sender, CustomDrawNodeCheckBoxEventArgs e) { e.Node.DisabledCheckBox(DisableNodeCheckBoxRule, e); } /// <summary> /// BeforeCheckNode事宜 /// </summary> void LHTree_BeforeCheckNode(object sender, CheckNodeEventArgs e) { e.Node.DisabledSetCheckBox(DisableNodeCheckBoxRule, e); } /// <summary> /// Disable TreeListNode規矩 /// </summary> /// <param name="node"></param> /// <returns></returns> private bool DisableNodeCheckBoxRule(TreeListNode node) { bool _disable = false; if (OpLampCfgList.Count > 0) { string _cabId = OpLampCfgList[0].CabID; NodeType _curType = node.GetNodeType(); if (_curType == NodeType.Lamp)//當節點是燈類型且父節點KEYID等於_cabId時刻,屏障Checkbox { _disable = node.ParentNode.ParentNode.GetKeyID().Equals(_cabId); } if (_curType == NodeType.Pole)//當節點是桿類型且父節點KEYID等於_cabId時刻,屏障Checkbox { _disable = node.ParentNode.GetKeyID().Equals(_cabId); } if (_curType == NodeType.Cab && node.GetKeyID().Equals(_cabId))//當節點是箱類型KEYID等於_cabId時刻,屏障Checkbox { _disable = true; } if (_curType == NodeType.Area || _curType == NodeType.CabsGroupRoot)//當節點類型等於地區或許根節點時刻,屏障Checkbox { _disable = true; } } return _disable; }
代碼運轉後果以下:
願望本文代碼能對年夜家有所贊助!