[DevExpress] Treelist Control's check box

Source: Internet
Author: User
Tags first row

Copyright notice: Author: jiankunking Source: http://blog.csdn.net/jiankunking The author and Csdn share, welcome reprint, but without the consent of the author must retain this paragraph statement, and in the article page obvious location to the original text connection.

The Treelist control can display both the tree structure and other data columns, that is, to establish a parent-child relationship expansion or contraction on one column, and also to display the contents of other columns.
The node and columns concepts are introduced in Treelist, the first column is the tree structure, the rest is column columns, and any column can be displayed as a tree structure column (that is, dragged to the first row).
implementing Multi-level tree--data source binding
Add the columns to be displayed in Treelist (the first column is the tree structure, the other columns are the data column), and specify FieldName as the database column name
Specifies that the Keyfieldname property is the primary key, and the Parentfieldname property is a tree-like grouping column. Note If the column specified by Parentfieldname is null, the tree may be confusing (only one root node, and the other child nodes for this node)
Bind data with Treelist.datasource = DataTable
A tree control is a control that uses a high frequency. The following two features are often required for property controls:
1.TreeList has a checkbox, and the node has three states (all child nodes are selected, all child nodes are not selected, and a subset of the child nodes are selected). This is easily accomplished with the Devxpress treelist control.
Set TreeList.OptionsView.ShowCheckBoxes = TRUE//Whether the checkbox is displayed
Set TreeList.OptionsBehavior.AllowIndeterminateCheckState = true; Sets whether the node has an intermediate state, that is, a subset of the child nodes are selected, and a subset is not selected
After setting these two properties, the Treelist is implemented with a checkbox and there are three states of the node.
2. Select the parent node or child node that affects each other, such as selecting the parent node to select all child nodes. Two events Afterchecknode and Beforechecknode bound to a treelist
DevExpress treelist to display a check box in front of a node, you have to modify the property optionsview->showcheckboxes=true
The rules for the child nodes of a check box that are consistent with the parent node are:
1, select a node, the node's child nodes are all selected
2. When a node is canceled, all child nodes of the node are deselected
3, when a node's child nodes are all selected, the node selects
4, when a node's child node is not all selected, the node does not select
[CSharp]  View Plain  copy   #region   node pre-select event     private void treelist1_ Beforechecknode (object sender, devexpress.xtratreelist.checknodeeventargs e)     {         if  (e.prevstate == checkstate.checked)         {            e.State  = checkstate.unchecked;        }         else        {             e.State = CheckState.Checked;        }    }     #endregion        #region   node selected after event     private  Void treelist1_afterchecknode (Object sender, devexpress.xtratreelist.nodeeventargs e)    &NBSp {        setcheckedchildnodes (e.node, e.node.checkstate);        setcheckedparentnodes (e.node, e.node.checkstate);    }      #endregion        #region   Setting sub-node status     private void  Setcheckedchildnodes (Devexpress.xtratreelist.nodes.treelistnode node, checkstate check)      {        for  (int i = 0; i <  node. nodes.count; i++)         {             node. Nodes[i]. checkstate = check;             Setcheckedchildnodes (node. Nodes[i], check);        }    }    # endregion       #region   Set parent node State &NBSP;&NBsp  private void setcheckedparentnodes (devexpress.xtratreelist.nodes.treelistnode node,  Checkstate check)     {        if  (node. Parentnode != null)         {             bool b = false;             CheckState state;            for   (Int i = 0; i < node. parentnode.nodes.count; i++)             {                 state =  ( CheckState) node. Parentnode.nodes[i]. checkstate;                if  ( !check. Equals (state))                 {                     b = !b;                    break;                 }             }             if  (b)   

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.