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!
Instead of overwriting the text like this:
you could append it, like this:
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
StringBuilderand assigning it afterwards, like this:You could also use LINQ, which would make the whole thing a little shorter: