Пример #1
0
        /// <summary>
        /// 填充Tree
        /// </summary>
        /// <param name="ParentID">父级编号</param>
        /// <param name="dt">格式,三列,Id,Name,ParentId,只要顺序一样就可以了</param>
        public void Fill(DataTable dt, object ParentID)
        {
            DropDownControl.Size = new Size(200, 300);



            DataTable temptbl  = dt.Copy();
            DataView  viewinfo = new DataView(temptbl);

            viewinfo.RowFilter = temptbl.Columns[2].ColumnName + " = " + ParentID;

            DropDownTree tree = DropDownControl;

            //DropDownNode root = new DropDownNode(-1, "==请选择==");
            //tree.Nodes.Clear();
            //tree.Nodes.Add(root);


            if (viewinfo.Count > 0)
            {
                foreach (DataRowView drv in viewinfo)
                {
                    DropDownNode node = new DropDownNode(Convert.ToInt32(drv[0]), drv[1].ToString());
                    tree.Nodes.Add(node);
                    ComboBoxTreeTree(node, drv[0], drv, dt);
                }
            }
            if (tree.Nodes.Count > 0)
            {
                tree.Nodes[0].Expand();
                SelectedByValue(viewinfo[0][0], viewinfo[0][1]);
            }

            //cbxTree.SelectedByValue(1, "==请选择==");
        }
Пример #2
0
        private void ComboBoxTreeTree(DropDownNode ParentNode, object ParentID, DataRowView ParentDV, DataTable dt)
        {
            DataTable temptbl  = dt.Copy();
            DataView  viewinfo = new DataView(temptbl);

            viewinfo.RowFilter = temptbl.Columns[2].ColumnName + " = " + ParentID;
            foreach (DataRowView drv in viewinfo)
            {
                DropDownNode node2 = new DropDownNode(Convert.ToInt32(drv[0]), drv[1].ToString());
                ParentNode.Nodes.Add(node2);
                ComboBoxTreeTree(node2, drv[0], drv, dt);
            }
        }
Пример #3
0
        private TreeNode SearchNode(TreeNodeCollection Nodes, DropDownNode SearchFor)
        {
            if (SearchFor != null)
            {
                foreach (DropDownNode node in Nodes)
                {
                    if (node.Id == SearchFor.Id)
                    {
                        return(node);
                    }
                    else
                    {
                        TreeNode found = SearchNode(node.Nodes, SearchFor);

                        if (found != null)
                        {
                            return(found);
                        }
                    }
                }
            }

            return(null);
        }
Пример #4
0
 /// <summary>
 /// 根据值来查找
 /// </summary>
 /// <param name="value">值</param>
 /// <param name="text">Text可以随便写,当然,最好是什么就写什么</param>
 public void SelectedByValue(object value, object text)
 {
     DropDownNodeValue = new DropDownNode(Convert.ToInt32(value), text.ToString());
 }