private void InitializeTreeView() { ICFTree.BeginUpdate(); ICFTree.Nodes.Add("Parent"); ICFTree.Nodes[0].Nodes.Add("Child 1"); ICFTree.Nodes[0].Nodes.Add("Child 2"); ICFTree.Nodes[0].Nodes[1].Nodes.Add("Grandchild"); ICFTree.Nodes[0].Nodes[1].Nodes[0].Nodes.Add("Great Grandchild"); ICFTree.EndUpdate(); }
private void TreeButton_Click_1(object sender, EventArgs e) { try { // SECTION 1. Create a DOM Document and load the XML data into it. XmlDocument dom = new XmlDocument(); dom.Load(Application.StartupPath + "\\sample.xml"); // SECTION 2. Initialize the TreeView control. ICFTree.Nodes.Clear(); ICFTree.Nodes.Add(new TreeNode(dom.DocumentElement.Name)); TreeNode tNode = new TreeNode(); tNode = ICFTree.Nodes[0]; // SECTION 3. Populate the TreeView with the DOM nodes. AddNode(dom.DocumentElement, tNode); // SECTION 4. Create a new TreeView Node with only the child nodes. XmlNodeList nodelist = dom.SelectNodes("//child"); //XmlDocument cDom = new XmlDocument(); //cDom.LoadXml("<children></children>"); //foreach (XmlNode node in nodelist) //{ // XmlNode newElem = cDom.CreateNode(XmlNodeType.Element, node.Name, node.LocalName); // newElem.InnerText = node.InnerText; // cDom.DocumentElement.AppendChild(newElem); //} // //ICFTree.Nodes.Add(new TreeNode(cDom.DocumentElement.Name)); //tNode = ICFTree.Nodes[1]; //AddNode(cDom.DocumentElement, tNode); ICFTree.ExpandAll(); Objektliste = nodelist; Objektzahl = Objektliste.Count; Ausgabe.Text = Objektzahl.ToString(); } catch (XmlException xmlEx) { MessageBox.Show(xmlEx.Message); } catch (Exception ex) { MessageBox.Show(ex.Message); } }