Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. how to add a now treenode in the following code?

how to add a now treenode in the following code?

Scheduled Pinned Locked Moved C#
data-structuresxmltutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    samidhas
    wrote on last edited by
    #1

    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); } } --------------------------------------------------------------------------

    M 1 Reply Last reply
    0
    • S samidhas

      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); } } --------------------------------------------------------------------------

      M Offline
      M Offline
      Malcolm Smart
      wrote on last edited by
      #2

      :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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups