Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WPF
How can I loop through an observablecollection using a foreach loop???
Posted 28-Dec-12 1:33am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

for xample you can leverage this snippet:
ObservableCollection<string> obsColl=new ObservableCollection<string>(){"1","2","3"};
foreach(var data in obsColl)
{
Console.WriteLine(data);
}
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

You could convert the items to a List and then try obcolls.ToList().ForEach(i => i.DoStuff());.
  Permalink  
Comments
Richard Deeming at 26-Jan-15 10:25am
   
This question is from December 2012 - over two years ago!
Abhinav S at 26-Jan-15 10:36am
   
It appeared suddenly and and answered it.
Richard Deeming at 26-Jan-15 10:38am
   
Solution #2 pushed it up the list.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

private ObservableCollection calculate = new ObservableCollection();
 
foreach (Calculations calc in calculate)
{
//access the property
mailing.Body += calc.Result + "\n";
}
 
public class Calculations
{
    private string _results;
 
    public string Result
    {
        get { return this._results; }
        set { this._results = value; }
    }
}
  Permalink  
v2
Comments
Richard Deeming at 26-Jan-15 10:25am
   
This question is from December 2012 - over two years ago!
Member 10798081 at 26-Jan-15 13:10pm
   
I landed to this answer at work today, so I thought I'd post my solution so that the next guy who has the same problem could see a variety of the same solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 495
1 Sergey Alexandrovich Kryukov 479
2 OriginalGriff 360
3 CHill60 280
4 CPallini 250
0 Sergey Alexandrovich Kryukov 10,017
1 OriginalGriff 9,495
2 Peter Leow 5,241
3 Kornfeld Eliyahu Peter 3,373
4 Maciej Los 3,076


Advertise | Privacy | Mobile
Web04 | 2.8.150327.1 | Last Updated 26 Jan 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100