Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6932857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:45:31+00:00 2026-05-27T11:45:31+00:00

I am currently trying to populate a treeview from xml that is returned to

  • 0

I am currently trying to populate a treeview from xml that is returned to me from a web request. When the response comes in I am manipulating the data so that the XML is in this layout:

<GroupList>
    <Group>
        <GroupName>my first test group</GroupName>
        <GroupID>djnsldgnljsdngljsdngljns</GroupID>
        <AccessLevel>high</AccessLevel>
        <SubGroup>
            <SubGroupName>my first test subgroup</SubGroupName>
            <SubGroupID>djnsldgnljsdngljsdngljns</SubGroupID>
        </SubGroup>
    </Group>
    <Group>
        <GroupName>my second test group</GroupName>
        <GroupID>djnsldgnljsdngljsdngl</GroupID>
        <AccessLevel>high</AccessLevel>
        <SubGroup>
            <SubGroupName>my second test subgroup</SubGroupName>
            <SubGroupID>DBXRdjnsldgnljsdngljsdngl</SubGroupID>
        </SubGroup>
        <SubGroup>
            <SubGroupName>my second test subgroup1</SubGroupName>
            <SubGroupID>EJdjnsldgnljsdngljsdngl42</SubGroupID>
        </SubGroup>
    </Group>
</GroupList>

All I want to do is display the groupName and then you are able to expand and view the subgroups. Currently I have got it “sort of” working but its all in one linear view. Here is my code I currently have:

  xmlDoc.LoadXml(response2);

  groupsTreeView.Nodes.Clear();
  groupsTreeView.Nodes.Add(new
  TreeNode(xmlDoc.DocumentElement.InnerText));
  TreeNode tNode = new TreeNode();
  tNode = (TreeNode)groupsTreeView.Nodes[0];

  addTreeNode(xmlDoc.DocumentElement, tNode);

  groupsTreeView.ExpandAll();

//This function is called recursively until all nodes are loaded
    private void addTreeNode(XmlNode xmlNode, TreeNode treeNode)
    {
        XmlNode xNode;
        TreeNode tNode;
        XmlNodeList xNodeList;
        if (xmlNode.HasChildNodes) //The current node has children
        {
            xNodeList = xmlNode.ChildNodes;

            for (int x = 0; x <= xNodeList.Count - 1; x++)
            //Loop through the child nodes
            {
                xNode = xmlNode.ChildNodes[x];
                groupsTreeView.Nodes.Add(new TreeNode(xNode.Value));
                tNode = groupsTreeView.Nodes[x];
                addTreeNode(xNode, tNode);
            }
        }
        else //No children, so add the outer xml (trimming off whitespace)
            treeNode.Text = xmlNode.OuterXml.Trim();
    }

This image is what the above code looks like when browsed on my system locally:

enter image description here

Any suggestions, im quite lost and it’s doing my head in!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:45:31+00:00Added an answer on May 27, 2026 at 11:45 am

    You could try using this using the linq xml(System.Xml.Linq):

        private TreeNode TNGroups(XElement xml)
        {
            TreeNode node = new TreeNode();
            foreach (XElement group in xml.Descendants("Group"))
            {
                TreeNode tnGroup = new TreeNode(group.Element("GroupName").Value);
                node.Nodes.Add(tnGroup);
                foreach (XElement subgroup in group.Elements("SubGroup"))
                {
                    TreeNode tnSubGroup = new TreeNode(subgroup.Element("SubGroupName").Value);
                    tnGroup.Nodes.Add(tnSubGroup);
                }
            }
            return node;
        }
    

    You would call it like this myTreeView.Nodes.Add(TNGroups(groupsXML)).

    To load you XML into an element just use XElement.Load.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to populate an UITableView from a plist downloaded from the internet.
I am currently trying to populate a cursor in the procedure. like that :
I am trying to populate a dropdownlist with data pulled from a .resx file.
Im currently trying to read an XML file and populate an observable collection, but
I'm trying to populate a table structure with around 5 fields of data from
I am trying to populate a number of UITextFields with data. Currently, I am
I currently trying to find a solution, how to ensure that a test fails
I'm currently trying to read in an XML file, make some minor changes (alter
I'm currently trying to pass a mono threaded program to multithread. This software do
I am currently trying to interface with a USB audio device from user land.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.