[DevExpress] disable TreeListNode CheckBox and treelistnode

Source: Internet
Author: User

[DevExpress] disable TreeListNode CheckBox and treelistnode

In actual development, you need to set the node uncheckable according to the conditions. You can view the DevExpress document and find that the combined use of the CustomDrawNodeCheckBox and BeforeCheckNode events can be achieved, generally, the rules that cannot be checked when setting nodes are the same, so code is slightly encapsulated.

Key code:

/// <Summary> /// disable CheckBox /// description /// use it in the CustomDrawNodeCheckBox event /// </summary> /// <param name = "tree"> TreeList </param> /// <param name = "conditionHanlder"> DeleGate </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> /// the CheckBox of the forbidden node // description /// use this method in the BeforeCheckNode event /// </summary> /// <param name =" tree "> TreeListNode </param> // <param name =" conditionHanlder "> DeleGate </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 ;}}

Example:

/// <Summary> // CustomDrawNodeCheckBox event // </summary> void LHTree_CustomDrawNodeCheckBox (object sender, CustomDrawNodeCheckBoxEventArgs e) {e. node. disabledCheckBox (DisableNodeCheckBoxRule, e);} // <summary> // BeforeCheckNode event // </summary> void dispatch (object sender, CheckNodeEventArgs e) {e. node. disabledSetCheckBox (DisableNodeCheckBoxRule, e );} /// <summary> /// Disable TreeListNode rule // </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) // when the node is of the Lamp type and the parent node KEYID is equal to _ cabId, block Checkbox {_ disable = node. parentNode. parentNode. getKeyID (). equals (_ cabId);} if (_ curType = NodeType. pole) // when the node is of the Pole type and the parent node KEYID is equal to _ cabId, the Checkbox {_ disable = node is blocked. parentNode. getKeyID (). equals (_ cabId);} if (_ curType = NodeType. cab & node. getKeyID (). equals (_ cabId) // when the node is of the Box Type KEYID equal to _ cabId, block Checkbox {_ disable = true;} if (_ curType = NodeType. area | _ curType = NodeType. cabsGroupRoot) // when the node type is equal to the region or root node, block Checkbox {_ disable = true ;}} return _ disable ;}

Code effect:

. Csharpcode ,. csharpcode pre {font-size: small; color: black; font-family: Las LAS, "Courier New", courier, monospace; background-color: # ffffff; /* white-space: pre ;*/}. csharpcode pre {margin: 0em ;}. csharpcode. rem {color: #008000 ;}. csharpcode. kwrd {color: # 0000ff ;}. csharpcode. str {color: #006080 ;}. csharpcode. op {color: # effecc0 ;}. csharpcode. preproc {color: # cc6633 ;}. csharpcode. asp {background-color: # ffff00 ;}. csharpcode. html {color: #800000 ;}. csharpcode. attr {color: # ff0000 ;}. csharpcode. alt {background-color: # f4f4f4; width: 100%; margin: 0em ;}. csharpcode. lnum {color: #606060 ;}

Hope this is helpful!


Q: How does the DEVExpress TreeList control bind data? Which event triggers binding? Now

Bind
Private void initTree ()
{

String sqltree = "select fitemid id, fnumber code, fname name, fparentid parentid from T_ITEM where fitemclassid = 4 and fdeleted = 0 and substring (fnumber, 1, 1) = '8' and fdetail = 0 ";
DataTable dtTree = SqlFunc. ExecSQL (sqltree );
TreeList1.DataSource = dtTree;
TreeList1.Columns ["id"]. Visible = false;
TreeList1.Columns ["parentid"]. Visible = false;
TreeList1.ExpandAll ();
GridView1.OptionsView. AllowCellMerge = true;
}
Click Event
Private void treelistpolicfocusednodechanged (object sender, DevExpress. XtraTreeList. FocusedNodeChangedEventArgs e)
{
DataRowView drv = (DataRowView) treeList1.GetDataRecordByNode (treeList1.FocusedNode );
DataRow dr = drv. Row;
Int p = Convert. ToInt32 (dr [0]);
..................
}
 
How to bind DevExpress in C # To XtraTreeList Parent and Child Nodes

This. treeList. DataSource = dt;

This. treeList. ParentFieldName = "Father_City_Id ";

This. treeList. KeyFieldName = "CityId ";

This is almost the case.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.