zoukankan      html  css  js  c++  java
  • DevExpress控件TreeList的复选框 .

    DevExpress的TreeList要想在节点前面显示复选框,得修改属性OptionsView->ShowCheckBoxes=True

    复选框的子节点与父节点统一的规则有:

    1,选择某一节点时,该节点的子节点全部选择

    2,取消某一节点时,该节点的子节点全部取消选择

    3,某节点的子节点全部选择时,该节点选择

    4,某节点的子节点未全部选择时,该节点不选择

    private void treeList1_AfterCheckNode(object sender, NodeEventArgs e) {
                SetCheckedChildNodes(e.Node, e.Node.CheckState);
                SetCheckedParentNodes(e.Node, e.Node.CheckState);
            }
            private void treeList1_BeforeCheckNode(object sender, CheckNodeEventArgs e) {
                e.State = (e.PrevState == CheckState.Checked ? CheckState.Unchecked : CheckState.Checked);
            }
            private void SetCheckedChildNodes(TreeListNode node, CheckState check) {
                for(int i = 0; i < node.Nodes.Count; i++) {
                    node.Nodes[i].CheckState = check;
                    SetCheckedChildNodes(node.Nodes[i], check);
                }
            }
            private void SetCheckedParentNodes(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;
                        }
                    }
                    node.ParentNode.CheckState = b ? CheckState.Indeterminate : check;
                    SetCheckedParentNodes(node.ParentNode, check);
                }
            }

     private void GetCheckedID(TreeListNode parentNode)
            {
                if (parentNode.Nodes.Count == 0)
                {
                    return;//递归终止
                }


                foreach (TreeListNode node in parentNode.Nodes)
                {
                    if (node.CheckState == CheckState.Checked)
                    {
                        DataRowView drv = treeList1.GetDataRecordByNode(node) as DataRowView;//关键代码
                        if (drv != null)
                        {
                            int GroupID= (int)drv["GroupID"];
                            lstCheckedOfficeID.Add(GroupID);
                        }


      private void btnOK_Click(object sender, EventArgs e)
            {
                
               
                this.lstCheckedOfficeID.Clear();


                if (treeList1.Nodes.Count > 0)
                {
                    foreach (TreeListNode root in treeList1.Nodes)
                    {
                        GetCheckedOfficeID(root);
                    }
                }


                string idStr = string.Empty;
                foreach (int id in lstCheckedOfficeID)
                {
                    idStr += id + " ";
                }


            }

                    }
                    GetCheckedOfficeID(node);
                }
            }

  • 相关阅读:
    leetcode 48. Rotate Image
    leetcode 203. Remove Linked List Elements 、83. Remove Duplicates from Sorted List 、82. Remove Duplicates from Sorted List II(剑指offer57 删除链表中重复的结点) 、26/80. Remove Duplicates from Sorted ArrayI、II
    leetcode 263. Ugly Number 、264. Ugly Number II 、313. Super Ugly Number 、204. Count Primes
    leetcode 58. Length of Last Word
    安卓操作的一些问题解决
    leetcode 378. Kth Smallest Element in a Sorted Matrix
    android studio Gradle Build速度加快方法
    禁用gridview,listview回弹或下拉悬停
    Android Studio找不到FragmentActivity类
    安卓获取ListView、GridView等滚动的距离(高度)
  • 原文地址:https://www.cnblogs.com/lovenan/p/2817572.html
Copyright © 2011-2022 走看看