how to add a now treenode in the following code?
-
if i want to insert a now node name an value , by entering it in the text box, and after cliking on button the node should be add to the tree view -------------------------------------------------------------------- private void Form1_Load(object sender, System.EventArgs e) { button1.Text = "Populate the TreeView with XML"; button1.SetBounds(8, 20, 200, 20); treeXml.Height = 600; treeXml.Width = 400; grpbox = new GroupBox(); grpbox.Height = 600; grpbox.Width = 400; grpbox.SetBounds(500, 2, 700, 600); grpbox.Visible = true; grpbox.Dock.Equals(Right); grpbox.Show(); this.Controls.Add(grpbox); } private void ConvertXmlNodeToTreeNode(XmlNode xmlNode, TreeNodeCollection treeNodes) { TreeNode newTreeNode = treeNodes.Add(xmlNode.Name); switch (xmlNode.NodeType) { case XmlNodeType.ProcessingInstruction: case XmlNodeType.XmlDeclaration: newTreeNode.Text = "<?" + xmlNode.Name + " " + xmlNode.Value + "?>"; break; case XmlNodeType.Element: if (xmlNode.Name.ToLower().Equals("node") == true) { newTreeNode.Text = "<" + xmlNode.Attributes["label"].Value.ToString() + ">"; } else newTreeNode.Text = "<" + xmlNode.Name + ">"; break; case XmlNodeType.Attribute: newTreeNode.Text = xmlNode.Name; // newTreeNode.Text = "ATTRIBUTE: " + xmlNode.Name; break; case XmlNodeType.Text: case XmlNodeType.CDATA: newTreeNode.Text = xmlNode.Value; break; case XmlNodeType.Comment: newTreeNode.Text = "<!--" + xmlNode.Value + "-->"; break; } if (xmlNode.Attributes != null) { foreach (XmlAttribute attribute in xmlNode.Attributes) { ConvertXmlNodeToTreeNode(attribute, newTreeNode.Nodes); } } foreach (XmlNode childNode in xmlNode.ChildNodes) { ConvertXmlNodeToTreeNode(childNode, newTreeNode.Nodes); } } --------------------------------------------------------------------------
-
if i want to insert a now node name an value , by entering it in the text box, and after cliking on button the node should be add to the tree view -------------------------------------------------------------------- private void Form1_Load(object sender, System.EventArgs e) { button1.Text = "Populate the TreeView with XML"; button1.SetBounds(8, 20, 200, 20); treeXml.Height = 600; treeXml.Width = 400; grpbox = new GroupBox(); grpbox.Height = 600; grpbox.Width = 400; grpbox.SetBounds(500, 2, 700, 600); grpbox.Visible = true; grpbox.Dock.Equals(Right); grpbox.Show(); this.Controls.Add(grpbox); } private void ConvertXmlNodeToTreeNode(XmlNode xmlNode, TreeNodeCollection treeNodes) { TreeNode newTreeNode = treeNodes.Add(xmlNode.Name); switch (xmlNode.NodeType) { case XmlNodeType.ProcessingInstruction: case XmlNodeType.XmlDeclaration: newTreeNode.Text = "<?" + xmlNode.Name + " " + xmlNode.Value + "?>"; break; case XmlNodeType.Element: if (xmlNode.Name.ToLower().Equals("node") == true) { newTreeNode.Text = "<" + xmlNode.Attributes["label"].Value.ToString() + ">"; } else newTreeNode.Text = "<" + xmlNode.Name + ">"; break; case XmlNodeType.Attribute: newTreeNode.Text = xmlNode.Name; // newTreeNode.Text = "ATTRIBUTE: " + xmlNode.Name; break; case XmlNodeType.Text: case XmlNodeType.CDATA: newTreeNode.Text = xmlNode.Value; break; case XmlNodeType.Comment: newTreeNode.Text = "<!--" + xmlNode.Value + "-->"; break; } if (xmlNode.Attributes != null) { foreach (XmlAttribute attribute in xmlNode.Attributes) { ConvertXmlNodeToTreeNode(attribute, newTreeNode.Nodes); } } foreach (XmlNode childNode in xmlNode.ChildNodes) { ConvertXmlNodeToTreeNode(childNode, newTreeNode.Nodes); } } --------------------------------------------------------------------------
:doh: :doh:
9:53 5 Feb '08 how to add a now treenode in the following code? - samidhas 11:04 4 Feb '08 i want to insert a new node regarding this code.but insert is not working.. - samidhas 10:32 4 Feb '08 how to insert a new node in a tree view programatically? - samidhas
I reckon it's time to put some effort into this and be a little bit more specific with your problem.We violated nature and our children have to pay the penalty Don't go near the water children... Johnny Cash - 1974