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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:10:16+00:00 2026-06-15T17:10:16+00:00

I have a list like this ID | Name | Title | ManagerID 1

  • 0

I have a list like this

  • ID | Name | Title | ManagerID

  • 1 | Peter | CEO | Null

  • 2 | Eric | Manager | 1
  • 3 | brad | Economy | 1
  • 4 | Pit | Sales | 2
  • 5 | Mike | Secretary| 4
  • 6 | Mac | copier | 5
  • 7 | Ben | Board | Null

This list can be infinite. The null values in this are because they have no Manager.
How can I add this to a treeview and get all the parentnode and subnodes correctly?

Need to accomplish this in a loop, and cannot change the database where it comes from,
I want to do something like?

private void treew(TreeNode treeNode, List<Employees> employ)
    {
        foreach (Employees option in employ)
        {
            TreeNode nodeOutput;
    //Add parent node
            foreach (Employees optionItems in employ)
            {
                if (option.ID == optionItems.ManagerID)
                {
        //Add childnode
                    TreeNode nodeOption;
                    nodeOutput.Nodes.Add(nodeOption);
                }
            }
            treeNode.Nodes.Add(nodeOutput);
        }
    }
  • 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-06-15T17:10:17+00:00Added an answer on June 15, 2026 at 5:10 pm
    private List<Employees> employees;
    private void treew(TreeNode root, int? managerID)
    {
        foreach (Employees option in employ.Where(x => x.MangerID == managerID))
        {
            TreeNode nodeOutput;
            treew(nodeOutput, option.ID);
            root.Nodes.Add(nodeOutput);
        }
    }
    

    Either pass in the root node of your TreeView to the first call, or create another version which takes the TreeView as the first argument and does pretty much the same thing.

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

Sidebar

Related Questions

I have a list like this: <select name=select_list_name id=list_id> <option value=>Select Option</option> <option value=value1>Option
I have a structure that roughly looks like this: List<ProductLine> -> ID Name ...
I have a list of objects that looks like this : ID:2000 Title:Title 1
I have a list of numbers on a table like this: n | Title---
I have the dropdown list like this <?php echo $form->dropdownList($customers,'customer_name', CHtml::listData(Customers::model()->findAll(), 'id', 'customer_name'), array(
I have a list like this: <ul> <li> <span>USA:</span> Newyork <span>USA:</span> Dallas </li> <li>
I have a list like this Dim emailList as new List(Of String) emailList.Add(one@domain.com) emailList.Add(two@domain.com)
I have a list like this: ['Ww','Aa','Bb','Cc','ww','AA','BB','CC'] And continuing in such a pattern, with
Suppose I have a list like this <ul> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li>
Within my code I have list items like this; <div id=content> <ul class=kwicks> <li

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.