-2

hi i have a question to treeview.

I have a List liste and the treeview with the name treeLic. Now I want to fill this treeview with this list. Can I do this and how?

XmlReader xr = XmlReader.Create(new StringReader(final_output));

           while (xr.Read())
           {
               switch (xr.Name)
               {
                   case "FEATURE":
                       if (xr.HasAttributes)
                       {
                           while (xr.MoveToNextAttribute())
                           {
                               if (xr.Name == "NAME")
                               {
                                   liste.Add(xr.Value);
                               }
                           }
                       }
                       break;

               }
           }

treeLic. ????? //fill this treeview with this list liste
Tarasov
  • 3,625
  • 19
  • 68
  • 128

2 Answers2

2
var nodes = XDocument.Load(fileName)
            .Descendants("FEATURE")
            .Select(f => new TreeNode((string)f.Attribute("NAME")))
            .ToArray();

treeLic.Nodes.AddRange(nodes);
EZI
  • 15,209
  • 2
  • 27
  • 33
1

Try this out.

XmlReader xr = XmlReader.Create(new StringReader(final_output));

       while (xr.Read())
       {
           switch (xr.Name)
           {
               case "FEATURE":
                    TreeNode root = MyTreeView.Nodes.Add("FEATURE");
                   if (xr.HasAttributes)
                   {
                       while (xr.MoveToNextAttribute())
                       {
                           if (xr.Name == "NAME")
                           {
                               TreeNode workingNode = root.Nodes.Add(xr.Value.ToString());
                               liste.Add(xr.Value);
                           }
                       }
                   }
                   break;

           }
       }
Dev
  • 960
  • 2
  • 15
  • 35