开发者

How to use data put in an ObservableCollection class?

I am building a small program in C#. I am new to programming and and can't seem to understand how to do this. I have a ObservableCollection class and I only manage to add data to it.

 public class Destinations : ObservableCollection<Destination>
{
    public Destinations()
        开发者_如何学Go: base()
     { Add(new Destination("from", "to", distance, total_distance, "no reason"));
...
 Destinations d;
 d = new Destinations();
 destinations.ItemsSource = d;
 d.Add(new Destination(lines[i], lines[i + dim / 2], distance, dist, null));

How can I access the information I have put in the collection. I've searched through the methods and found nothing helpful. I'm sure it's my fault but please help me.


The ObservableCollection has an Indexer (aka Item property). Like an array or a list you just supply the index of the element you want to retrieve it....

Destinations d; d = new Destinations(); d.Add(new Destination(lines[i], lines[i + dim / 2], distance, dist, null));

Destination d0 = d[0];

http://msdn.microsoft.com/en-us/library/ms668604.aspx


Do you want to retrieve the items you added to the collection? You can use the indexer for that, or enumerate it in a for each, ... What is the problem which you're having?

Also, if you bind the collection to a control (i.e., a list control), the elements of the collection should be bound to the control as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜