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

The Archive Base Latest Questions

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

There are plenty of methods to convert datatable into treeview (treenode) like this .

  • 0

There are plenty of methods to convert datatable into treeview (treenode) like this. But is there any way to do create a datatable maintaining hierarchy. For ex. if TreeNode is like

A-A1
 -A2-A21
    -A22
B-B1
 -B2-B21
 -B3-B31
    -B32-B321
        -B322
    -B33
 -B4

should look like following in datatable. Then i can either save it in the databse or show it to the user in a datagrid.

enter image description here

All column can have take string values.

Is there any way so i can pass a treenode to a function & it will create datatble like this dynamically. treenode structure will change everytime that’s why i can not hardcode it. Suppose i have a recursive function like this.

public void CreateData(TreeNode trn)
{

   foreach(TreeNode t in trn.Nodes)
   {
       CreateData(t);
   }

}

i am facing difficulty in understanding flow of code for recursive function.
any suggestion is appreciated.

Thanks.

  • 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-27T06:31:10+00:00Added an answer on May 27, 2026 at 6:31 am

    Here’s a pseudo code, hope it will help you to deal with your problem

    private void getNodeList()
    {
        //This will hold your node text
        List<string> nodeTextList = new List<string>();
        //loop through all teeview nodes
        foreach(TreeNode rootNode in treeView.Nodes)
        {
           //Add root node to list
           nodeTextList.Add(rootNode.Text);
           //Do recursive getter to get child nodes of root node
           getChildNodes(rootNode, nodeTextList);
    
        }
        //Do with nodeTextList what ever you want, for example add to datatable.
    }
    
    private void getChildNodes(TreeNode rootNode, List<string> nodeTextList)
    {
       foreach(TreeNode childNode in rootNode.Nodes)
       {
           //Add child node text
           nodeTextList.Add(childNode.Text);      
           getChildNodes(childNode, nodeTextList);
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This problem smells like there should be an answer in graph theory, but it
There are plenty of threads on how to create a Method using Reflection.Emit but
There's plenty of information on running Java apps as services, but I need to
There are plenty of tutorials how to create multilanguage RESX files and how to
I know there are plenty of other questions addressing the same problem, but since
I'm calling web service (my web service) like this: var request = WebRequest.Create(Options.ServerUri +
There are plenty of script/tools for counting line of code, and some to count
There are plenty of PHP frameworks out there as many of you know, and
There are plenty of 'pretty-printing' visualization libraries for Javascript. E.g. those listed here. Googling
Dynamic languages are on the rise and there are plenty of them: e.g. Ruby,

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.