473,399 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Traversing a Collection

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.

May 1 '06 #1
3 1307
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

"James" <ya*********@yahoo.com.au> schreef in bericht
news:11**********************@j73g2000cwa.googlegr oups.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.

May 1 '06 #2
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
"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.

May 1 '06 #3
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.

May 2 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: w.p. | last post by:
Hello! I want change default tab traversing in my app. But i don't know how to do it :( Belowe i include simple example - i want change default tab order: radiobutton "mode11" -> radiobutton...
2
by: Jim Cobban | last post by:
I am using Xerces to read an XML file and load it into a DOM so I can update it and subsequently serialize the updated DOM. The problem I have is that as I traverse the DOM I would like to inform...
3
by: Plamen Valtchev | last post by:
This is my problem: From JavaScript I want to find the list of all defined/loaded JavaScript functions/objects/names within the current scope (html page in a browser). the page could contain...
1
by: Josh | last post by:
Hi, I am using an OCX from VB6 that has a routine that outputs a collection. If "Params" is defined as a collection in VB6, The following statements (in the VB6 debug window) works:...
4
by: nmosafi | last post by:
I have a datagrid that I am binding to a custom collection, and I am having problems with data binding in an ASP.NET datagrid (1.1 framework). As a simple example, imagine a class called...
4
by: elziko | last post by:
I have a class ("ClassB") that inherits from 'ClassA' which inherist from UserControl. I then put ClassB onto a form. Is it then possible to tracerse all the controls on the form that inherit...
4
by: plmanikandan | last post by:
Hi, I am new to link list programming.I need to traverse from the end of link list.Is there any way to find the end of link list without traversing from start(i.e traversing from first to find the...
30
by: asit | last post by:
We kno that data can be pushed onto the stack or popped 4m it. Can stack be traversed ??
1
by: somcool | last post by:
I am facing an error while traversing a query in MS Access Details - When I click a button, a form which has the query opens up. There are certain fields which are in the form of combo box in the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.