MyTreeNode buildTree(dynamic node) { MyTreeNode n = new MyTreeNode((string)node.name); n.data = node; n.Expand(); if (node.children != null) { foreach (var c in node.children) { n.Nodes.Add(buildTree(c)); } } return(n); }
private void TreeInvCCode_Load() { configPath = Application.StartupPath + "\\配置文件\\Config.xml"; DataKeep.Serialize(configPath, false, ref param); foreach (Map map in param.Maps) { if (!dictParam.ContainsKey(map.Name)) { dictParam.Add(map.Name, map.Value); } } dt = new DataTable(); foreach (DataColumn col in sql.dataTable.Columns) { if (dictParam.ContainsKey(col.ColumnName)) { string value = dictParam[col.ColumnName]; dt.Columns.Add(value); } } Dictionary <string, string> dict = new Dictionary <string, string>(); treeView1.LabelEdit = true; foreach (DataRow dr in dataTable.Rows) { MyTreeNode node = tree; int i = 0; foreach (var bat in Encoding.ASCII.GetBytes(dr["cInvCCode"].ToString())) { if (node.node.ContainsKey(bat)) { node = node.node[bat]; } else { MyTreeNode treeNode = new MyTreeNode(); treeNode.num = bat; node.node.Add(bat, treeNode); node = treeNode; } } if (!cInvStatus.ContainsKey(dr["cInvCCode"].ToString())) { cInvStatus.Add(dr["cInvCCode"].ToString(), Convert.ToBoolean(dr["bInvCEnd"].ToString())); } node.treeNode = new TreeNode(); node.cInvCCode = dr["cInvCCode"].ToString(); node.treeNode.Text = dr["cInvCCode"].ToString() + " " + dr["cInvCName"].ToString(); node.bInvCEnd = Convert.ToBoolean(dr["bInvCEnd"].ToString()); } TreeNode treeNode1 = new TreeNode(); treeNode1.Text = "全部"; treeView1.Nodes.Add(treeNode1); SetTree(tree, treeNode1); foreach (TreeNode node in treeView1.Nodes) { node.Expand(); foreach (TreeNode twonode in node.Nodes) { twonode.Expand(); } } }