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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:42:23+00:00 2026-05-11T03:42:23+00:00

I have a large result set assembled in a parent/child relationship. I need to

  • 0

I have a large result set assembled in a parent/child relationship. I need to walk the tree and display the results to the user.

I’ve done this before using recursion, but because my result set may be large, I want to avoid the possibility of receiving a StackOverflowException.

I found the following example on MSDN which uses a Stack. The problem I’m having is because a stack is last-in first-out, my data doesn’t appear properly. I’d like it to look like the following:

 LeveL 1 Level 1.1 Level 1.1.1  Level 1.1.2  Level 1.2  Level 1.2.1  Level 1.2.2 

But it looks like:

 LeveL 1 Level 1.2  Level 1.2.2  Level 1.2.1  Level 1.1  Level 1.1.2  Level 1.1.1  

Any ideas?

Here is an example of my code. Assuming the DataTable dt has the following columns: ID, ParentID, and Text

    private struct Item     {         public string Text;         public int ID;         public int ParentID;     }      private void BuildView()     {         Stack<Item> itemTree = new Stack<Item>(40);          //Get All Parent Nodes         DataView dv = new DataView(dt);         dv.RowFilter = 'ParentID = 0';          //Add the parent nodes to the stack         foreach (DataRowView drv in dv)         {             Item item = new Item();             item.Text = drv['Text'].ToString();             item.ID = drv['ID'].ToString();             item.ParentID = drv['ParentID'].ToString();             itemTree.Push(item);         }          //Go through the stack one node at a time         while (itemTree.Count > 0)         {             Item currentItem = itemTree.Pop();             Debug.WriteLine(currentItem.Text);              //Get children of current node             dv.RowFilter = String.Format('ParentID = {0}', currentItem.ID);             if (dv.Count > 0)             {                 //Add child nodes to the stack                 foreach (DataRowView drvChild in dv)                 {                     Item item = new Item();                     item.Text = drvChild['Text'].ToString();                     item.ID = drvChild['ID'].ToString();                     item.ParentID = drvChild['ParentID'].ToString();                     itemTree.Push(item);                 }             }         }      } 
  • 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. 2026-05-11T03:42:23+00:00Added an answer on May 11, 2026 at 3:42 am

    Push your items onto the stack in the reverse order, i.e. 2 before 1.

    Example:

    // suppose I want to push children[] onto the stack  for (int i = children.Length - 1; i >= 0; i--) {    stack.Push(children[i]); } 

    To do this in your code, try the following for-each statement:

    foreach (DataRowView drvChild in dv.Reverse()) 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a large result set in a table where I am applying
I have a result set I pull from a large database: $result = mysql_query($sql);
I have large set of flow charts and workflow diagrams. I want to draw
In my application I have large area (≈5000x5000pts) and I must allow user to
Consider I have large library package with sophisticated tree of private or package modules
Interpolating Large Datasets I have a large data set of about 0.5million records representing
I have to read in a large record set, process it, then write it
Let's say I have a large set of data within which each datum has
I have a large string (with text). I need to split it into a
I have a large set of data saved in a long list. This is

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.