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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:54:12+00:00 2026-06-05T15:54:12+00:00

I want to organize a set of Object ( MyPlugin ) in a TreeView

  • 0

I want to organize a set of Object (MyPlugin) in a TreeView by Category.
Actually i’m adding them to the TreeView using the following method :

  internal static TreeNode AddPluginNode(TreeView parent, AbstractEnvChecker plugin)
  {
      TreeNode created = new TreeNode(plugin.Name) { Tag = plugin };
      parent.Nodes.Add(created);
      return created;
  }

// I’m using the Tag so i can conserve the MyPlugin Type for each Node

And this is the method i’m using to populate my TreeView from a List<MyPlugin> :

internal static void FillTreeViewWithPlugins(TreeView p_TreeView, Type p_Type, IList<AbstractEnvChecker> p_List)
{
    TreeNode v_TreeNode;
    if (p_TreeView != null)
    {
        p_TreeView.Nodes.Clear();
        foreach (object p_Item in p_List)
        {
            if (p_Item.GetType().IsSubclassOf(p_Type))
            {
                v_TreeNode = null;
                v_TreeNode = AddPluginNode(p_TreeView, p_Item as AbstractEnvChecker);

            }
        }
    }
}

Everything works well, but the problem is that the previous method displays a simple TreeView that contains then list of MyPlugin. I want to classify them by a property called Category (String MyPlugin.Category).

So i should proceed like this :

TreeNode testNodeA = new TreeNode("A"); 
TreeNode testNodeB = new TreeNode("B");
TreeNode testNodeC = new TreeNode("C");
TreeNode[] array = new TreeNode[] { testNodeA, testNodeB, testNodeC };
TreeNode cat = new TreeNode("Categorie X", array);
treeView1.Nodes.Add(cat);
  1. If i want to keep my previous code, i cannot know how many plugins will i add to each category so i cannot use an Array with fixed dimensions …
  2. I can’t use List because the TreeNode constructor accepts only Array and the TreeView.Nodes.Add method accepts only TreeNode …

How can i do it ?

  • 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-05T15:54:13+00:00Added an answer on June 5, 2026 at 3:54 pm

    Build a dictionary of categories on the fly while creating the nodes. Later, add only these nodes to the tree. The steps are as follows:

    Declare a dictionary like that

    Dictionary<string, TreeNode> categoryNodes = new ...;
    

    The key is the category name, the value is the TreeNode for the category.

    While iterating over all the MyPlugins in your list, check whether there’s a category node in the dictionary and create one if there’s not:

    if (!categoryNodes.ContainsKey(p_Item.Category))
        categoryNodes[p_Item.Category] = new TreeNode(p_Item.Category);
    

    Add the new TreeNode for the plugin under the respective category node:

    v_TreeNode = AddPluginNode(categoryNodes[p_Item.Category], p_Item as AbstractEnvChecker);
    

    In the end, add all the values of the dictionary to the tree:

    foreach (string key in categoryNodes.Keys)
    {
        p_TreeView.Nodes.Add(categoryNodes[key]);
    }
    

    Your code should look like this:

    internal static void FillTreeViewWithPlugins(TreeView p_TreeView, Type p_Type, IList<AbstractEnvChecker> p_List)
    {
        Dictionary<string, TreeNode> categoryNodes = new Dictionary<string, TreeNode>();
        TreeNode v_TreeNode;
    
        if (p_TreeView != null)
        {
            p_TreeView.Nodes.Clear();
    
            foreach (object p_Item in p_List)
            {
                if (p_Item.GetType().IsSubclassOf(p_Type))
                {
                    if (!categoryNodes.ContainsKey(p_Item.Category))
                        categoryNodes[p_Item.Category] = new TreeNode(p_Item.Category);
    
                    v_TreeNode = null;
                    v_TreeNode = AddPluginNode(categoryNodes[p_Item.Category], p_Item as AbstractEnvChecker);    
                }
            }
    
            foreach (string cat in categoryNodes.Keys)
                p_TreeView.Nodes.Add(categoryNodes[cat]);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have panel that is using group layout to organize some label. I want
When you automate web UI testing you want to organize your tests so that
want to know why String behaves like value type while using ==. String s1
I want to organize somehow my iPhone game's level-views, but I simply cannot (without
I'm getting values from mysql database, I want to organize it with each row
I have a set of custom PropertyDescriptor that I want to add categories too
I have a set of custom user controls, of type ChartControl. I want to
I'm attempting to set up a windows-based FTP server using Apache FTPServer, however I
I have a data set that is organized in the following manner: Timestamp|A0001|A0002|A0003|A0004|B0001|B0002|B0003|B0004 ...
Suppose I have 5 local commits. I want to push only 2 of them

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.