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

The Archive Base Latest Questions

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

I have the following table structure it might not be a correct structure but

  • 0

I have the following table structure it might not be a correct structure but unfortunatly that’s what I was given.

id |  Name  | Parent  | Status
 1    First     0       Active
 2    Child     1       Active
 3    2Child    2       Inactive

Logic:

  1. Load Root by Parent = 0 and Status

  2. OnPopulate load child by parent ID and status for every levels after root

    my issue is if the status is “Inactive” and I want to see what options are inactive I can’t because the first 2 options are active. What I need is to be able to view in my treeview all the levels down to the option that is Inactive or Active.

I have tried the following sql statement

select distinct
        m.Id,
        m.Name,
        m.Parent,
        m.[Status]
from mytable m
where m.Parent = 3 and m.[Status] = 'I'
union
select 
        Id,
        Name,
        Parent,
        [Status]
from mytable
where ID in(select distinct
        o.ID
from mytable o
where o.ID = 3 and o.[Status] = 'I') and Parent = 3

I have ran out of ideas in sql and coding to figure this out..hope someone could guide me in the right direction..thanks

Also tried this in code:

    protected void mytree_TreeNodePopulate(object sender, TreeNodeEventArgs e)
    {
        //this is just a class that loads the values from db
        MYList templist = new ListSyFamily();
        templist.LoadAll();//(ddlStatus.SelectedValue, Convert.ToInt32(e.Node.Value));

        foreach (temp temp in templist)
        {
            if (temp.Status == ddlStatus.SelectedValue && temp.Parent == Convert.ToInt32(e.Node.Value))
            {
                TreeNode child = new TreeNode();
                child.Text = temp.Description;
                child.Value = temp.Id.ToString();
                if (child.ChildNodes.Count == 0)
                    child.PopulateOnDemand = true;

                child.ToolTip = "Ver sub-opciones";
                //child.SelectAction = TreeNodeSelectAction.SelectExpand;

                child.CollapseAll();

                e.Node.ChildNodes.Add(child);
            }
        }
    }
  • 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:41:39+00:00Added an answer on May 27, 2026 at 11:41 am

    Here is how we handle this.

    Assume that you have a class called MyRecord to hold each row of data from the DB:

    public class MyRecord
    {
        public int Id {get; set; }
        public int ParentId {get; set; }
    
        public string Name { get; set; }
        public string Status { get; set; }
    
        // The children of this node
        public MyRecordCollection Children = new MyRecordCollection();
    }
    

    Then you have a collection type to hold these records indexed by their id:

    public class MyRecordCollection : System.Collections.Generic.Dictionary<int, MyRecord>
    {
    
    }
    

    Here is the code (retrieval from the DB not shown) to preprocess the records and then add them to the tree:

            MyRecordCollection cAllRecords;
            MyRecordCollection cParentRecords = new MyRecordCollection();
    
            // This is a method that just loads the records
            cAllRecords = LoadAllRecords();
    
            // Cycle through each of the records
            foreach (MyRecord oRecord in cAllRecords.Values)
            {
                if (oRecord.Id == 0)
                {
                    // If the record is a parent record, add it to the list of parents
                    cParentRecords.Add(oRecord.Id, oRecord);
                }
                else
                {
                    // Otherwise, add the current record to its parent's list of children
                    cAllRecords[oRecord.ParentId].Children.Add(oRecord.Id, oRecord);
                }
            }
    
            AddNodesToTree(cParentRecords, this.treeView1.Nodes);
    

    And finally, the recursive method for adding the records 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(MyRecordCollection cRecords, TreeNodeCollection cNodes)
        {
            foreach (MyRecord 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 have the following table structure CREATE TABLE `table` ( `id` int(11) NOT NULL
I have following table structure in my DB ID Name -------------------------- ID_1 Name1 ID1
I have following table structure: CREATE TABLE pilot_groups ( id INT PK, name VARCHAR(50),
I have the following table structure: Table Users ID | Name 1 | John
I have following table structure: Table: Plant PlantID: Primary Key PlantName: String Table: Party
I have the following table structure (in MySQL): DocID, Code, IsDup, DopOf , where
I have the following table structure. A | B | C I wish to
I have the following table structure, which is imported into an Entity Framework project:
I have the following MySQL table structure: num field company phone website 1 Gas
I have no control over database schema and have the following (simplified) table structure:

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.