DevExpress treelist Control check box introduction

Source: Internet
Author: User

The Treelist control can display both the tree structure and other data columns, that is, to establish a parent-child relationship expand or shrink on one column, and to display the contents of other columns.

The node and columns concepts are introduced in the Treelist, the first column is the tree structure, the rest are columns of data, and any columns can be displayed as tree structure columns (that is, dragged to the first column).

Implement multilevel tree--data source binding

Add Treelist to display columns (first column tree structure, other column columns), and specify FieldName as database column name

Specifies the Keyfieldname property as the primary key and the Parentfieldname property as a tree grouping column. Note that if the column specified by Parentfieldname is null, the tree may be confused (with only one root node and other child nodes for this node)

Binding data with Treelist.datasource = DataTable

A tree control is a control that uses a high frequency. The following two features are often required for a property control:

1.TreeList has a checkbox and the node has three states (all of the child nodes are selected, all the child nodes are not selected, and some of the child nodes are selected). This functionality is easy to implement with Devxpress treelist controls.

Set TreeList.OptionsView.ShowCheckBoxes = TRUE//whether checkbox is displayed

Set TreeList.OptionsBehavior.AllowIndeterminateCheckState = true; Sets whether a node has an intermediate state, that is, a subset of the child nodes are selected, and some of the child nodes are not selected

After you set these two properties, you implement the treelist with a checkbox and there are three states of nodes.

2. Select the parent node or child nodes to affect each other, such as selecting the parent node to select all child nodes. Binding treelist two events Afterchecknode and Beforechecknode

DevExpress treelist to display a check box in front of the node, you have to modify the property optionsview->showcheckboxes=true

The rules for a child node of a check box that are consistent with the parent node are:

1. When selecting a node, the node's child nodes are all selected

2, when canceling a node, the node's child nodes are all deselected

3, when the child nodes of a node are all selected, the node selects

4, when the child node of a node is not all selected, the node does not select

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/net/

Event private void Treelist1_beforechecknode (object sender, DevExpress.XtraTreeList.CheckNodeEventArgs e) Before #region node is checked  
     {if (e.prevstate = = checkstate.checked) {e.state = checkstate.unchecked;  
     else {e.state = checkstate.checked; The event private void Treelist1_afterchecknode (object sender, Devexpress.xtratreel when #endregion #region node is selected Ist.  
     Nodeeventargs e) {setcheckedchildnodes (E.node, e.node.checkstate);  
 Setcheckedparentnodes (E.node, e.node.checkstate); #endregion #region Set the child node state private void Setcheckedchildnodes (DevExpress.XtraTreeList.Nodes.TreeListNode n Ode, CheckState Check) {for (int i = 0; i < node. Nodes.count; i++) {node. Nodes[i].  
         CheckState = check; Setcheckedchildnodes (node.  
     Nodes[i], check); #endregion #region Set the parent node state 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) {node.  
         Parentnode.checkstate = checkstate.indeterminate; } else {node.  
         Parentnode.checkstate = check; } setcheckedparentnodes (node.  
     ParentNode, check); }} #endregion

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.