You need to implement IEnumerable to be able to do that. I have several small objects that have need for this enumerator, so I created an abstract ObjectCollection class that implements an IEnumerable interface for databinding controls. All you have to do is declare a new object collection, and pass in an array of your custom objects. Then in code behind, if you ever need to access an object from the collection, just use the GetObject(index) property. It will return as an object, but you can change the type in order to program more effectively.
i.e.
dim t as textbox = DirectCast(objCollection.GetObject(0), textbox)
' get text
dim strText = t.Text
The code is in VB, though it shouldn't be hard to translate. Visitthis post to view the ObjectCollection class.
0 comments:
Post a Comment