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 6933961
In Process

The Archive Base Latest Questions

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

I am trying to prepare the tree view control from folowing strings. US|New York|D.M.Street

  • 0

I am trying to prepare the tree view control from folowing strings.

    "US|New York|D.M.Street"
    "US|New York|ShoppingMall"
    "INDIA|Dehli|G.M. Road"
    "INDIA|Mumbai|Harbour Street"
    "US|Washington|WhiteHouse"
    "INDIA|Dehli|Rajpath"
    "INDIA|Mumbai|CST"

I want to populate the tree view from this collection in C#. in following manner

Country
|
US => NewYork   ==========>D.M.Street
|      |        ==========>ShoppingMall
       |
|      Washinton==========>WhiteHouse
|
INDIA=>Dehli    ==========>G.M. Road
      |         ==========>Rajpath
      |
      Mumbai    ==========>CST
                ==========>Harbour Street

how i can prepare this ? usning collection or else way?

  • 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:53:58+00:00Added an answer on May 27, 2026 at 11:53 am

    Here’s how I would approach this:

    Create a class and a collection to hold a nested hierarchy of elements (this can be expanded later if more detail is needed).

    public class Element
    {
        public Element(string Name)
        {
            this.Name = Name;
        }
        public string Name { get; set; }
    
        public ElementCollection Children = new ElementCollection();
    
        // This method is used to add the specified child name if it does not currently 
        // exist, or return the existing one if it does
        public Element AddOrFetchChild(string sName)
        {
            Element oChild;
            if (this.Children.ContainsKey(sName))
            {
                oChild = this.Children[sName];
            }
            else
            {
                oChild = new Element(sName);
                this.Children.Add(sName, oChild);
            }
            return oChild;
        }        
    
    }
    
    public class ElementCollection : System.Collections.Generic.Dictionary<string, Element>
    {
    
    }
    

    Then parse your data into the collection (note that this will support any level of nesting in your record structure without a need to modify the code):

            string[] asLines;
    
            // ToDo: Add code here to populate the collection of lines to process
    
            // Create a base element that makes popuplation of the elements easier
            Element BaseElement = new Element("");
    
            // Cycle through each of the lines
            foreach (string sLine in asLines())
            {
                // Get the components out of the line
                string[] asElements = sLine.Split("|");
    
                // Starting with the base element
                Element oParentElement = BaseElement;
    
                // Cycle through each of the elements that were found, adding the current value to the parent's 
                // collection of children, then using the new or found item as the parent for the next item in the list
                for (int nI = 0; nI < asElements.Length; nI++)
                {
                    oParentElement = oParentElement.AddOrFetchChild(asElements[nI]);
                }
            }
    
            // Finally, add the nodes to the tree recursively
            AddNodesToTree(BaseElement.Children, this.treeView1.Nodes);
    

    and this is the recursive method used to add the items to the tree

        /// <summary>
        /// A recursive method to add all of the records to the specified collection of nodes
        /// </summary>
        /// <param name="cRecords"></param>
        /// <param name="cNodes"></param>
        private void AddNodesToTree(ElementCollection cRecords, TreeNodeCollection cNodes)
        {
            foreach (Element oRecord in cRecords.Values)
            {
                TreeNode oNode = new TreeNode();
                oNode.Text = oRecord.Name;
                oNode.Tag = oRecord;
                cNodes.Add(oNode);
                // Now add the node's children if any
                if (oRecord.Children.Count != 0)
                {
                    AddNodesToTree(oRecord.Children, oNode.Nodes);
                }
            }
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to go, I was trying to prepare client server in go
trying to convert all my old mysql_* operations into new and, from what i've
I'm trying to execve a process that reads from stdin. I want to prepare
I am new to Javascript. Recently I am trying to prepare a checkform function,
I'm trying how best to prepare my SQLite SQL strings in PHP. The SQLite3
I'm trying to prepare a view to be shown by update the text in
I am trying to do following $statement = $conn->prepare('SELECT * FROM myTable'); $statement->execute(); if(!($row
I am trying to do prepared statements as follows: $stmt = $mysqli->prepare(SELECT COUNT(*) FROM
Trying to prepare good build environment for my js library. According to reviews on
I am trying to prepare my activity's how to use windows but I am

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.