Array of ArrayList

G

Guest

Hi

I declared a global ArrayList called TotalClients in a module of my VB.NET application
Later in one of the forms when I finish entering individual client information, I initialise a Array called IndividualClient which contains 7 elements or items. Then I insert the IndividualClient array in the TotalClients ArrayList.

The question is, how can I retrive the IndividualCLient elements or items from the TotalCLients array list ?

Any comments are appreciated

Sincerely

Paol
 
G

Guest

The question is, how can I retrive the IndividualCLient elements or items from the TotalCLients array list ??

Like this:

Dim MyArrayList As New ArrayList
Dim MyCustomer(7) As Object

MyCustomer(0) = "CustomerName"
MyArrayList.Add(MyCustomer)

Debug.WriteLine(String.Format("Customer name is {0}",
CStr(CType(MyArrayList(0), Object())(0))))

But :

That design is a shocker. You really want to create at least a
structure

Public Structure Customer
Dim Name as string
Dim Address as string
End Structure

And create either a customer collection or if you want to be lazy just
use the ArrayList.

Dim MyArrayList As New ArrayList
Dim c as New Customer

With C
.Name = "Sir Bill Gates"
.Address = "1 Microsoft Way"
End With

MyArrayList.Add(c)
Dim msg as String
msg = String.Format("Customer Name is {0}", Ctype(MyArrayList(0),
Customer).Name))

Debug.Writeline(Msg)


This allows for a more strongly typed scenario, which would be
strengthened thru use of a customer collection. Just using an array
leads to the possibility that the name could end up in the address
index, etc, etc.

hth
Richard
 
C

Cor

Hi Ptreves,

I realised me I had a sample from a arraylist in an arraylist, almost the
same
\\\
Dim x As New ArrayList
For i As Integer = 0 To 9
Dim y As New ArrayList
For j As Integer = 0 To 4
y.Add(Chr(j + 65))
Next
x.Add(y)
Next
MessageBox.Show(DirectCast(x(2), ArrayList)(2).ToString)
///

I hope this helps a little bit?

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top