|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Traversing a CollectionI have created several Collection objects which inherit from System.Collections.CollectionBase but up until now I've been able to process them according to the order I populate them from a database. Now I want to be able to traverse backwards and forward through items in my collection and apart from loading the whole collection into an array or Arraylist, I can't work out how. eg. I have items like "Book" and a collection like "Books". I can easily process the items with For each book as Book in m_Books ' do stuff Next But I need more flexibility and the collection must have some kind of index inherited from the CollectionBase Maybe the arraylist idea is the best but I'm hoping that someone can tell me about something more elegant that I must have at my fingertips ? James. James,
In Net is a complete main namespace for Database handling, that is System.Data. (ADONET) In that are a lot of classes for the handling in memory. A major part of those are than again collection classes. There is probably a lot of time taken in that, it is a major part. Why would you do it on your own and ask us to help you with that? Cor Show quoteHide quote "James" <yajames2***@yahoo.com.au> schreef in bericht news:1146464152.352714.120900@j73g2000cwa.googlegroups.com... > Hi. > > I have created several Collection objects which inherit from > > System.Collections.CollectionBase > > but up until now I've been able to process them according to the order > I populate them from a database. > > Now I want to be able to traverse backwards and forward through items > in my collection and apart from loading the whole collection into an > array or Arraylist, I can't work out how. > > eg. I have items like "Book" and a collection like "Books". > > I can easily process the items with > For each book as Book in m_Books > ' do stuff > Next > > But I need more flexibility and the collection must have some kind of > index inherited from the CollectionBase > > Maybe the arraylist idea is the best but I'm hoping that someone can > tell me about something more elegant that I must have at my fingertips > ? > > James. > James,
Your custom collection class should implement a strongly-typed Item property that returns an item from the collection using an index. Here is an example: Default Public Property Item(ByVal Index As Integer) As clsStudent Get Return CType(Me.List.Item(Index), clsStudent) End Get Set(ByVal Value As clsStudent) Me.List.Item(Index) = Value End Set End Property Kerry Moorman Show quoteHide quote "James" wrote: > Hi. > > I have created several Collection objects which inherit from > > System.Collections.CollectionBase > > but up until now I've been able to process them according to the order > I populate them from a database. > > Now I want to be able to traverse backwards and forward through items > in my collection and apart from loading the whole collection into an > array or Arraylist, I can't work out how. > > eg. I have items like "Book" and a collection like "Books". > > I can easily process the items with > For each book as Book in m_Books > ' do stuff > Next > > But I need more flexibility and the collection must have some kind of > index inherited from the CollectionBase > > Maybe the arraylist idea is the best but I'm hoping that someone can > tell me about something more elegant that I must have at my fingertips > ? > > James. > > Yes!!. Thanks Kerry, that worked well (and very simple which is good).
I think that property will have to be a standard entry in every collection class I can lay my hands on :-) Thanks again.
VB2005 Pro Edition--Data Sources window is disabled when viewing forms
Adding a Web Reference changes DataTypes ??? Accessing one dimension of a multidimensional array Regular Expression Desperately needing direction with EncoderParameters and saving images under different compression/q Maximum Form Height? Ent Library. Substitute data from app.config? Displaying copied file names in textbox problem opening Excel file with Shell My.Computer.Network.IsAvailable question |
|||||||||||||||||||||||