Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more: , +
I am working with the OpcNetApi libraries, and have a conundrum in my mind.
I have an object [MyObject] that is a collection of Items [type Item] with base type ItemId, which I use to create a subscription;, to read the values I get a return [type ItemValue] with base type ItemId so that becomes [MyObjectValues].
Each of these type Item and type ItemValue has a Correlated UniqueID to match them up.

I have multiple objects that are known as MyObject which consists of multiple Items. [Basically an Array consisting of an Array of Objects] List< List<T> > where List<T> is the MyObjectItems, and List< List<T> > is an encapsulating list of MyObjects.

I should also add that each Item or ItemValue needs to have a corresponding propertyName (so I can bind PropertyName (for my column in a grid, ItemValue.Value for the column value) so a row of the grid would consist of the List<T> and additional rows are the list of the List<T> .


I am doing two things with the resultant data, binding to a winforms application and also updating a database.
What kinds of approaches are best for this scenario in order to quickly find one item in those lists so my OnChangeEvent which may come with one ItemValue can quickly access the exact item, set its value and also allow me to bind with Winform reflecting the new values automagically.

Simple is best, fact is really good, best of both worlds even better.
Small samples , good hints , good reads are all welcome , thank you in advance.
Posted
Updated 15-May-15 8:57am
v3
Comments
PIEBALDconsult 15-May-15 14:55pm    
Dictionary.
stixoffire 15-May-15 15:18pm    
I was looking at Dictionary - should I use one for each ItemValue and Item - keying on the UniqueID, and then how to associate that with the propertyName - another dictionary ?
So basically I am joining these objects, and looking up an item so I can change a value with info from from a continuously running process, and have those changes in the dictionary reflected in my bound control ..
PIEBALDconsult 15-May-15 15:25pm    
Whatever makes sense for the application. You may want a Dictionary of Dictionaries -- an app I'm working on now does that.
stixoffire 15-May-15 16:02pm    
Your app changes the values , and you see those changes reflected in Winform without rebinding ? I am liking this to some extent b/c dictionary has fast lookup.

1 solution

I usually implement in the List<t> object a custom "this" method, for example:

C#
public class MyItemCollection : List<Item>
{
  ....

  public Item this[String itemID]
  {
     foreach(Item i in this)
     {
        if(Item.ItemID == itemID) return i;
     }
     // return null if Item not found for supplied itemID
     return null;
  }

  ....
}


Then you can make calls like
C#
MyObjectCollection col = new MyObjectCollection();
// Populate collection

String itemID = "MyItem";
Item item = col[itemID];
 
Share this answer
 
v3
Comments
stixoffire 15-May-15 16:10pm    
for fast lookup to change a value, maybe I could do this and also with a dictionary for the lookup. Dictionary<key, list="">
Both your answer and PIEbalds are helping me alot - I think yours encapsulates the objects nicely. I will do some working with this and see what happens as it seems simple enough to test out.
stixoffire 15-May-15 16:17pm    
I have a get Accessor is expected on the foreach , is this supposed to be a get property?
stixoffire 15-May-15 16:39pm    
I set it as a get.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900