Multi-Dimensional Array

  • Thread starter Thread starter C CORDON
  • Start date Start date
C

C CORDON

I have an arrar something like this:{{"Dog", "Cat", "Mouse"},{"1", "2",
"3"}}

I want to enter all thos into a combo box (dropdown list) so that Item "Dog"
has a value of 1, and so on.

How do i iterate trough that array in order to :

Items.Add ("1", "Dog"), etc...

Thanks.
 
Hi,

Bind to an arraylist filled with a class that holds the data you
want.


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim ar As New ArrayList

ar.Add(New ComboItems("Dog", 1))

ar.Add(New ComboItems("Cat", 2))

ar.Add(New ComboItems("Mouse", 3))

ComboBox1.DataSource = ar

ComboBox1.DisplayMember = "Animal"

ComboBox1.ValueMember = "Val"

End Sub

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

Dim ci As ComboItems

Try

ci = DirectCast(ComboBox1.SelectedItem, ComboItems)

Debug.WriteLine(String.Format("Display {0} Value {1}", ci.Animal, ci.Val))

Catch ex As Exception

End Try

End Sub



The class



Public Class ComboItems

Private mstrAnimal As String

Private mintVal As Integer

Public Property Animal() As String

Get

Return mstrAnimal

End Get

Set(ByVal Value As String)

mstrAnimal = Value

End Set

End Property

Public Property Val() As Integer

Get

Return mintVal

End Get

Set(ByVal Value As Integer)

mintVal = Value

End Set

End Property

Public Sub New(ByVal MyAnimal As String, ByVal MyVal As Integer)

mintVal = MyVal

mstrAnimal = MyAnimal

End Sub

End Class



Ken

--------------------------------------

I have an arrar something like this:{{"Dog", "Cat", "Mouse"},{"1", "2",
"3"}}

I want to enter all thos into a combo box (dropdown list) so that Item "Dog"
has a value of 1, and so on.

How do i iterate trough that array in order to :

Items.Add ("1", "Dog"), etc...

Thanks.
 
C CORDON said:
I have an arrar something like this:{{"Dog", "Cat", "Mouse"},{"1", "2",
"3"}}

I want to enter all thos into a combo box (dropdown list) so that Item
"Dog" has a value of 1, and so on.

How do i iterate trough that array in order to :

Items.Add ("1", "Dog"), etc...

\\\
Dim astr(,) As String = {{"Dog", "Cat", "Mouse"}, {"1", "2", "3"}}
For i As Integer = 0 To astr.GetLength(1) - 1
Me.ListBox1.Items.Add(astr(0, i) & " " & astr(1, i))
Next i
///
 

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

Back
Top