TreeNode chNode=new TreeNode("新节点的文本"); tvwTree1.currNode.Nodes.Add(chNode); 或者 System.Windows.Forms.TreeNode objTreeNode=new TreeNode(); objTreeNode.Text="新节点"; objTreeNode.Tag="新节点"; objTreeNode.ImageIndex=1; this.treeView1.Nodes.Add(objTreeNode); |
public static bool GetData() { mBoot = new TreeNode("参数化文件列表"); try { DataTableCollection dts = TlsHelper.GetTablesFormXml("tlscad.trv"); DataTable cdt = dts["Class"]; DataTable sdt = dts["SubClass"]; int m = cdt.Rows.Count; for (int i = 0; i < m; i++) { DataRow cdr = cdt.Rows; TreeNode cnode = new TreeNode(cdr["Name"].ToString()); DataRow[] sdrs = sdt.Select("cid=" + cdr["cid"].ToString()); int n = sdrs.Length; for (int j = 0; j < n; j++) { DataRow sdr = sdrs[j]; TreeNode snode = new TreeNode(sdr["Name"].ToString()); snode.ImageIndex = 2; snode.SelectedImageIndex = 3; cnode.Nodes.Add(snode); } mBoot.Nodes.Add(cnode); } mBoot.ExpandAll(); return true; } catch { return false; } }// |