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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:12:21+00:00 2026-05-29T08:12:21+00:00

I have several foreach loops after each other in a larger foreach loop.. What

  • 0

I have several foreach loops after each other in a larger foreach loop.. What I’m wanting to do is to add each set of passes into a datalist/datasource.

foreach (HtmlNode cell in cells3)
{
    Dispatcher.BeginInvoke(() => textBlock4.Text = cell.InnerText);
}

foreach (HtmlNode cell in cells)
{
    Dispatcher.BeginInvoke(() => textBlock5.Text = cell.InnerText);
}

foreach (HtmlNode cell in cells2)
{
    Dispatcher.BeginInvoke(() => textBlock6.Text = cell.InnerText);
}

My current code goes through and dumps the results to the textblocks but it over-rights each other so it only displays the last result. So somehow I need to add them to variables or a datalist to display them separately in a list.

Thanks in advance!

  • 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-29T08:12:22+00:00Added an answer on May 29, 2026 at 8:12 am

    Instead of overwriting the text like this:

    textBlock4.Text = cell.InnerText
    

    you could append it, like this:

    textBlock4.Text += cell.InnerText
    

    A better (and faster, as it doesn’t use the slow DependencyProperty system as excessive as well as relieves the dispatcher) approach would be aggregating the text in a StringBuilder and assigning it afterwards, like this:

    StringBuilder sb = new StringBuilder();
    foreach (HtmlNode cell in cells3)
    {
        sb.AppendLine(cell.InnerText);
    }
    Dispatcher.BeginInvoke(() => textBlock4.Text = sb.ToString());
    sb.Clear();
    
    // reuse sb for the following loops as shown above
    

    You could also use LINQ, which would make the whole thing a little shorter:

    StringBuilder sb = cells3.Aggregate(
        new StringBuilder(),
        (sb, cell) => sb.AppendLine(cell.InnerText));
    
    Dispatcher.BeginInvoke(() => textBlock4.Text = sb.ToString());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hey guys, we have a loop that: 1.Loops over several thousand xml files. Altogether
I have a foreach loop which loops through an array (simpleXML nodes). This array
After reading several other questions, it looks like it's not advisable to have an
I have a List containing several keywords. I foreach through them building my linq
We have several different optimization algorithms that produce a different result for each run.
I have my sources split up in several directories, so for each directory I
I have written an importer which copies data from a flat table into several
i have a program which is using several threads to execute some task. Each
I have several ASP:TextBox controls on a form (about 20). When the form loads,
I have several RequiredFieldValidators in an ASP.NET 1.1 web application that are firing on

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.