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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:55:35+00:00 2026-06-13T22:55:35+00:00

suppose i have saved file path in database. now i want to show those

  • 0

suppose i have saved file path in database. now i want to show those file path through treeview. i found one sample that works fine but do not know when there will be huge data in database then treeview population will be hang or take too long. here i am giving the code. please check and tell which can be rectified as a result performance will be good when there will be huge data in db.

public static class MyDataBase
{
    private static List<string> fields = new List<string>();

    public static void AddField(string field)
    {
        fields.Add(field);
    }

    public static IList<string> FieldsInMyColumn()
    {
        return fields;
    }
}

public void CreateTreeView()
    {
        foreach (string field in MyDataBase.FieldsInMyColumn())
        {
            string[] elements = field.Split('\\');
            TreeNode parentNode = null;

            for (int i = 0; i < elements.Length - 1; ++i)
            {
                if (parentNode == null)
                {
                    bool exits = false;
                    foreach (TreeNode node in myTreeview.Nodes)
                    {
                        if (node.Text == elements[i])
                        {
                            exits = true;
                            parentNode = node;
                        }
                    }

                    if (!exits)
                    {
                        TreeNode childNode = new TreeNode(elements[i]);
                        myTreeview.Nodes.Add(childNode);
                        parentNode = childNode;
                    }
                }
                else
                {
                    bool exits = false;
                    foreach (TreeNode node in parentNode.Nodes)
                    {
                        if (node.Text == elements[i])
                        {
                            exits = true;
                            parentNode = node;
                        }
                    }

                    if (!exits)
                    {
                        TreeNode childNode = new TreeNode(elements[i]);
                        parentNode.Nodes.Add(childNode);
                        parentNode = childNode;
                    }
                }
            }

            if (parentNode != null)
            {
                parentNode.Nodes.Add(elements[elements.Length - 1]);
            }
        }
    }

 private void button1_Click(object sender, EventArgs e)
    {
        MyDataBase.AddField(@"c:\jsmith\project1\hello.cs");
        MyDataBase.AddField(@"c:\jsmith\project1\what.cs");
        MyDataBase.AddField(@"c:\jsmith\project2\hello.cs");
        MyDataBase.AddField(@"c:\jsmith\project1\tdp.cs");
        MyDataBase.AddField(@"c:\jsmith\project2\ship.cs");
        MyDataBase.AddField(@"d:\jsmith\project1\hello404.cs");
        MyDataBase.AddField(@"c:\jsmith1\project2\ship.cs");
        CreateTreeView();
    }

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-06-13T22:55:36+00:00Added an answer on June 13, 2026 at 10:55 pm

    Depending on your framework version, maybe you can try something like this :

    public void ProcessPath(IEnumerable<String> path,  TreeNodeCollection nodes)
    {
        if (!path.Any())
            return;
        var node = nodes.Cast<TreeNode>().FirstOrDefault(n => n.Text == path.First());
        if (node == null)
        {
            node = new TreeNode(text: path.First());
            nodes.Add(node);
        }
        ProcessPath(path.Skip(1),node.ChildNodes);
    }
    
    public void CreateTreeView()
    {
        foreach (string field in MyDataBase.FieldsInMyColumn())
            ProcessPath(field.Split('\\'),myTreeView.Nodes);
    }
    

    If you really have a huge amount of rows, you should probably look for a solution where you only load the child nodes upon click on a node

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

Sidebar

Related Questions

Suppose, I have saved some permissions in the database by using this code: RoleRepository
Suppose I have a 400K text file which I want to read from a
Suppose we have a Invoice that is saved in a draft state in a
I have a txt plain file that has a list of numbers. One number
Suppose there is a site where we are uploading images. Now, when we have
Suppose I have an .rda file created using save() . Example: save(mydata1, file =
I have downloaded and added this very simple, one file, php web file explorer
Suppose I have a local file that I am working on that is part
Suppose we have the following HTML file: <html xmlns=http://www.w3.org/1999/xhtml> <head> <title>Test iframe download</title> <script
In My program I have a file and then I read through all the

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.