473,836 Members | 1,514 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 6980
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
3059
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 Arraylist. I've very little experience working with datagrids and arraylists so im finding this...
11
2188
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 a new aspx page and on this new page i need to be able to access the items in my arraylist. Is this...
6
1842
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 below. private void checkArrayList() { ArrayList alSearchaddress; alSearchaddress =...
1
2598
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 time which of these parent/child nodes will occur. I have also looked at the XmlTextReader, but it...
14
18758
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
6777
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
8307
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 inside the ListBox, assuming the new values of the ArrayList. Obviously, if the new ArrayList is...
0
9671
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10854
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10558
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10600
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9387
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7794
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6981
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
4022
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3116
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.