Exemple #1
0
        public static TreeNode BuildChildNode(this TreeView treeView, string id, List <JNodeData> datas)
        {
            TreeNode  rootNode = new TreeNode(id);
            JNodeData rootData = datas.FirstOrDefault(row => row.Id == id);

            if (rootData != null)
            {
                rootNode.ToolTipText = rootData.Text;
                rootNode.Tag         = rootData.Tag;
            }
            var childrenNodeData = datas.Where(row => row.PId == id);

            if (childrenNodeData == null || childrenNodeData.Count() == 0)
            {
                return(rootNode);
            }
            foreach (JNodeData childNodeData in childrenNodeData)
            {
                TreeNode childNode = treeView.BuildChildNode(childNodeData.Id, datas);
                if (childNode != null)
                {
                    // childNode.ParentNode = rootNode;
                    rootNode.Nodes.Add(childNode);
                }
            }
            return(rootNode);
        }
Exemple #2
0
        public static TreeView BuildTree(this TreeView treeView, string connStr, string sql)
        {
            DataTable        table = SqlHelper.ExecuteDataTable(connStr, CommandType.Text, sql, null);
            List <JNodeData> datas = new List <JNodeData>();

            foreach (var item in table.Rows.Cast <DataRow>())
            {
                string    id   = item["ID"].Value <string>();
                string    pid  = item["PID"].Value <string>();
                string    name = item["Name"].Value <string>();
                JNodeData node = new JNodeData(id, pid, name, item);
                datas.Add(node);
            }
            treeView.Nodes.Add(treeView.BuildChildNode("0", datas));
            //treeView.Nodes.Add();
            return(treeView);
        }