473,549 Members | 2,588 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading Items in an ArrayList

I am using Visual Basic 2005.

I have created a two dimensional ArrayList named aSystem that is populated as
follows:-

aSystem.Add(New PickList(0, "Undefined" ))
aSystem.Add(New PickList(-1, "Standard UTM"))
aSystem.Add(New PickList(-2, "UTM-NAD83"))
aSystem.Add(New PickList(-3, "UTM-NAD27"))

and then other items are added to the ArrayList from a sorted recordset as
follows:-

Do Until ssTemp.EOF
aSystem.Add(New PickList(ssTemp .Fields("Primar yKey").Value, _
ssTemp.Fields(" Name").Value))
ssTemp.MoveNext ()
Loop

The structure of the PickList class is as follows:-

Public Structure PickList

Private mnPrimaryKey As Integer
Private msID As String

Public Sub New(ByVal PrimaryKey As Integer, ByVal ID As String)
mnPrimaryKey = PrimaryKey
msID = ID
End Sub

Public ReadOnly Property PrimaryKey() As Integer
Get
Return mnPrimaryKey
End Get
End Property

Public ReadOnly Property ID() As String
Get
Return msID
End Get
End Property

End Structure

I use the ArrayList to populate a ComboBox

With cboSystem
.DataSource = aSystem
.ValueMember = "PrimaryKey "
.DisplayMember = "ID"
End With

For the most part everything works fine; the ComboBox is populated with all
the data.

I have two problems...

1. I can't seem to read the items from the ArrayList directly. I would
expect to be
able to read the array something like this:

aSystem.Item(1)

but all I get back is:_

MagCalculator.P ickList: {MagCalculator. PickList} where

where MagCalculator is the name of the application.

How do I read the individual items of the two-dimensional ArrayList?

2. I want to sort the ArrayList but although there is an abundance of
information in MSDN on how to sort a one-dimensional ArrayList, there is no
information on how to sort a two-dimensional ArrayList.

As mentioned already, I subsequently populate a ComboBox with the two
dimensional ArrayList, and this seems to work fine except of course the list
isn't sorted.

If anyone could point me in the right direction, I'd be grateful.

Aug 16 '06 #1
3 6963
Hi Stuat,

I think you are mislead by the idea that there exists such a thing like

a "bidimensio nal" arraylist.

Here an example for your tasks. YOu can change the property being
compared
according to your needs.

-Tommaso


Public Class Form1
Inherits System.Windows. Forms.Form

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

Dim aSystem As New ArrayList
aSystem.Add(New PickList(0, "Undefined" ))
aSystem.Add(New PickList(-1, "Standard UTM"))
aSystem.Add(New PickList(-2, "UTM-NAD83"))
aSystem.Add(New PickList(-3, "UTM-NAD27"))

'1.Get items
Dim FirstPickList As PickList = DirectCast(aSys tem(0),
PickList)
With FirstPickList
Dim id As String = .ID
Dim PrimaryKey As Integer = .PrimaryKey
End With
'2.Sort Items
aSystem.Sort(Ne w ComparerForPick List)

End Sub

Class ComparerForPick List
Implements IComparer

Public Function Compare(ByVal x As Object, ByVal y As Object)
As Integer Implements System.Collecti ons.IComparer.C ompare

Dim PickList1 As PickList = DirectCast(x, PickList)
Dim PickList2 As PickList = DirectCast(y, PickList)

Return String.Compare( PickList1.ID, PickList2.ID)

End Function

End Class

Public Class PickList

Private mnPrimaryKey As Integer
Private msID As String

Public Sub New(ByVal PrimaryKey As Integer, ByVal ID As String)
mnPrimaryKey = PrimaryKey
msID = ID
End Sub

Public ReadOnly Property PrimaryKey() As Integer
Get
Return mnPrimaryKey
End Get
End Property

Public ReadOnly Property ID() As String
Get
Return msID
End Get
End Property

End Class

End Class



Stuart ha scritto:
I am using Visual Basic 2005.

I have created a two dimensional ArrayList named aSystem that is populated as
follows:-

aSystem.Add(New PickList(0, "Undefined" ))
aSystem.Add(New PickList(-1, "Standard UTM"))
aSystem.Add(New PickList(-2, "UTM-NAD83"))
aSystem.Add(New PickList(-3, "UTM-NAD27"))

and then other items are added to the ArrayList from a sorted recordset as
follows:-

Do Until ssTemp.EOF
aSystem.Add(New PickList(ssTemp .Fields("Primar yKey").Value, _
ssTemp.Fields(" Name").Value))
ssTemp.MoveNext ()
Loop

The structure of the PickList class is as follows:-

Public Structure PickList

Private mnPrimaryKey As Integer
Private msID As String

Public Sub New(ByVal PrimaryKey As Integer, ByVal ID As String)
mnPrimaryKey = PrimaryKey
msID = ID
End Sub

Public ReadOnly Property PrimaryKey() As Integer
Get
Return mnPrimaryKey
End Get
End Property

Public ReadOnly Property ID() As String
Get
Return msID
End Get
End Property

End Structure

I use the ArrayList to populate a ComboBox

With cboSystem
.DataSource = aSystem
.ValueMember = "PrimaryKey "
.DisplayMember = "ID"
End With

For the most part everything works fine; the ComboBox is populated with all
the data.

I have two problems...

1. I can't seem to read the items from the ArrayList directly. I would
expect to be
able to read the array something like this:

aSystem.Item(1)

but all I get back is:_

MagCalculator.P ickList: {MagCalculator. PickList} where

where MagCalculator is the name of the application.

How do I read the individual items of the two-dimensional ArrayList?

2. I want to sort the ArrayList but although there is an abundance of
information in MSDN on how to sort a one-dimensional ArrayList, there is no
information on how to sort a two-dimensional ArrayList.

As mentioned already, I subsequently populate a ComboBox with the two
dimensional ArrayList, and this seems to work fine except of course the list
isn't sorted.

If anyone could point me in the right direction, I'd be grateful.
Aug 16 '06 #2
Hi Stuart,

I think you are mislead by the idea that there exists such a thing like

a "bidimensio nal" arraylist.

Here an example for your tasks. YOu can change the property being
compared according to your needs.

-Tommaso

Public Class Form1
Inherits System.Windows. Forms.Form
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As

System.EventArg s) Handles Button1.Click
Dim aSystem As New ArrayList
aSystem.Add(New PickList(0, "Undefined" ))
aSystem.Add(New PickList(-1, "Standard UTM"))
aSystem.Add(New PickList(-2, "UTM-NAD83"))
aSystem.Add(New PickList(-3, "UTM-NAD27"))
'1.Get items
Dim FirstPickList As PickList = DirectCast(aSys tem(0),
PickList)
With FirstPickList
Dim id As String = .ID
Dim PrimaryKey As Integer = .PrimaryKey
End With
'2.Sort Items
aSystem.Sort(Ne w ComparerForPick List)
End Sub
Class ComparerForPick List
Implements IComparer

Public Function Compare(ByVal x As Object, ByVal y As Object)
As Integer Implements System.Collecti ons.IComparer.C ompare

Dim PickList1 As PickList = DirectCast(x, PickList)
Dim PickList2 As PickList = DirectCast(y, PickList)

Return String.Compare( PickList1.ID, PickList2.ID)

End Function

End Class
Public Class PickList
Private mnPrimaryKey As Integer
Private msID As String

Public Sub New(ByVal PrimaryKey As Integer, ByVal ID As String)

mnPrimaryKey = PrimaryKey
msID = ID
End Sub
Public ReadOnly Property PrimaryKey() As Integer
Get
Return mnPrimaryKey
End Get
End Property
Public ReadOnly Property ID() As String
Get
Return msID
End Get
End Property
End Class
End Class
Stuart ha scritto:
I am using Visual Basic 2005.

I have created a two dimensional ArrayList named aSystem that is populated as
follows:-

aSystem.Add(New PickList(0, "Undefined" ))
aSystem.Add(New PickList(-1, "Standard UTM"))
aSystem.Add(New PickList(-2, "UTM-NAD83"))
aSystem.Add(New PickList(-3, "UTM-NAD27"))

and then other items are added to the ArrayList from a sorted recordset as
follows:-

Do Until ssTemp.EOF
aSystem.Add(New PickList(ssTemp .Fields("Primar yKey").Value, _
ssTemp.Fields(" Name").Value))
ssTemp.MoveNext ()
Loop

The structure of the PickList class is as follows:-

Public Structure PickList

Private mnPrimaryKey As Integer
Private msID As String

Public Sub New(ByVal PrimaryKey As Integer, ByVal ID As String)
mnPrimaryKey = PrimaryKey
msID = ID
End Sub

Public ReadOnly Property PrimaryKey() As Integer
Get
Return mnPrimaryKey
End Get
End Property

Public ReadOnly Property ID() As String
Get
Return msID
End Get
End Property

End Structure

I use the ArrayList to populate a ComboBox

With cboSystem
.DataSource = aSystem
.ValueMember = "PrimaryKey "
.DisplayMember = "ID"
End With

For the most part everything works fine; the ComboBox is populated with all
the data.

I have two problems...

1. I can't seem to read the items from the ArrayList directly. I would
expect to be
able to read the array something like this:

aSystem.Item(1)

but all I get back is:_

MagCalculator.P ickList: {MagCalculator. PickList} where

where MagCalculator is the name of the application.

How do I read the individual items of the two-dimensional ArrayList?

2. I want to sort the ArrayList but although there is an abundance of
information in MSDN on how to sort a one-dimensional ArrayList, there is no
information on how to sort a two-dimensional ArrayList.

As mentioned already, I subsequently populate a ComboBox with the two
dimensional ArrayList, and this seems to work fine except of course the list
isn't sorted.

If anyone could point me in the right direction, I'd be grateful.
Aug 16 '06 #3
Thanks Pamela.

Wow! That was quick!

....and it worked. I would never had figured it out myself. You're a star.

Stuart

"pa***********@ libero.it" wrote:
Hi Stuat,

I think you are mislead by the idea that there exists such a thing like

a "bidimensio nal" arraylist.

Here an example for your tasks. YOu can change the property being
compared
according to your needs.

-Tommaso


Public Class Form1
Inherits System.Windows. Forms.Form

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

Dim aSystem As New ArrayList
aSystem.Add(New PickList(0, "Undefined" ))
aSystem.Add(New PickList(-1, "Standard UTM"))
aSystem.Add(New PickList(-2, "UTM-NAD83"))
aSystem.Add(New PickList(-3, "UTM-NAD27"))

'1.Get items
Dim FirstPickList As PickList = DirectCast(aSys tem(0),
PickList)
With FirstPickList
Dim id As String = .ID
Dim PrimaryKey As Integer = .PrimaryKey
End With
'2.Sort Items
aSystem.Sort(Ne w ComparerForPick List)

End Sub

Class ComparerForPick List
Implements IComparer

Public Function Compare(ByVal x As Object, ByVal y As Object)
As Integer Implements System.Collecti ons.IComparer.C ompare

Dim PickList1 As PickList = DirectCast(x, PickList)
Dim PickList2 As PickList = DirectCast(y, PickList)

Return String.Compare( PickList1.ID, PickList2.ID)

End Function

End Class

Public Class PickList

Private mnPrimaryKey As Integer
Private msID As String

Public Sub New(ByVal PrimaryKey As Integer, ByVal ID As String)
mnPrimaryKey = PrimaryKey
msID = ID
End Sub

Public ReadOnly Property PrimaryKey() As Integer
Get
Return mnPrimaryKey
End Get
End Property

Public ReadOnly Property ID() As String
Get
Return msID
End Get
End Property

End Class

End Class



Stuart ha scritto:
I am using Visual Basic 2005.

I have created a two dimensional ArrayList named aSystem that is populated as
follows:-

aSystem.Add(New PickList(0, "Undefined" ))
aSystem.Add(New PickList(-1, "Standard UTM"))
aSystem.Add(New PickList(-2, "UTM-NAD83"))
aSystem.Add(New PickList(-3, "UTM-NAD27"))

and then other items are added to the ArrayList from a sorted recordset as
follows:-

Do Until ssTemp.EOF
aSystem.Add(New PickList(ssTemp .Fields("Primar yKey").Value, _
ssTemp.Fields(" Name").Value))
ssTemp.MoveNext ()
Loop

The structure of the PickList class is as follows:-

Public Structure PickList

Private mnPrimaryKey As Integer
Private msID As String

Public Sub New(ByVal PrimaryKey As Integer, ByVal ID As String)
mnPrimaryKey = PrimaryKey
msID = ID
End Sub

Public ReadOnly Property PrimaryKey() As Integer
Get
Return mnPrimaryKey
End Get
End Property

Public ReadOnly Property ID() As String
Get
Return msID
End Get
End Property

End Structure

I use the ArrayList to populate a ComboBox

With cboSystem
.DataSource = aSystem
.ValueMember = "PrimaryKey "
.DisplayMember = "ID"
End With

For the most part everything works fine; the ComboBox is populated with all
the data.

I have two problems...

1. I can't seem to read the items from the ArrayList directly. I would
expect to be
able to read the array something like this:

aSystem.Item(1)

but all I get back is:_

MagCalculator.P ickList: {MagCalculator. PickList} where

where MagCalculator is the name of the application.

How do I read the individual items of the two-dimensional ArrayList?

2. I want to sort the ArrayList but although there is an abundance of
information in MSDN on how to sort a one-dimensional ArrayList, there is no
information on how to sort a two-dimensional ArrayList.

As mentioned already, I subsequently populate a ComboBox with the two
dimensional ArrayList, and this seems to work fine except of course the list
isn't sorted.

If anyone could point me in the right direction, I'd be grateful.

Aug 16 '06 #4

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

Similar topics

3
3037
by: Stephen | last post by:
I've got a datagrid with a remove button and I would like to add some code in the code behind page so as whenthe button is clicked the corresponding row in the datagrid is removed. The Datagrid is populated by the items in an arraylist shown in the code below. When the button is clicked I would also like the code to remove the items from the...
11
2151
by: Stephen | last post by:
I was wondering if someone can help me with an web application design problem. I have a aspx page which builds up an arraylist called addresses and outputs the values in the arraylist items to a datagrid. I am using the viewstate object to store the Arraylist items on the page on postback. My PROBLEM is that I need to redirect the user to...
6
1811
by: Stephen | last post by:
Im trying to carry work out an else if clause in the below method but i'm having a lot of difficulty getting the correct code which allows me to check and see if an arraylist items has text in it containing Address not supplied. Im trying to do something below but its not working properly. Can someone help me do this please. the code i use is...
1
2573
by: davis | last post by:
Hello, I am working in .Net C# and have an xml file similar to the one below. I have tried using a DataSet but get the error "The same table (Gid) cannot be the child table in two nested relations". The file has a number of parent nodes at the "<ShipmentHeader>" level, each of which have a number of child nodes. I will not know ahead of...
14
18735
by: budy_ludy | last post by:
Hi All, I am new to vb .net, I have an ArrayList and i store class objects in it, and later i want to retrieve each ArrayList items and type cast to the class, How can it be done ? I used CType for casting but it is throwing exception.
10
6752
by: pamelafluente | last post by:
Hi I have a sorted list with several thousands items. In my case, but this is not important, objects are stored only in Keys, Values are all Nothing. Several of the stored objects (might be a large number) have to be removed (say when ToBeRemoved = true). class SomeObj ToBeRemoved be a boolean field end class
1
8302
by: Refugnic | last post by:
I tried to fill a ListBox with a DataSource pointing to an ArrayList. It all works fine...up to one point. The ArrayList is dynamic, which means the contents of it change, during the course of program use. But instead of Updating the ListBox, virtually nothing happens. The items that were written into the ListBox during the first run remain...
0
7532
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7461
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
6055
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5101
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3509
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3491
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1956
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1068
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
776
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.