KenDickinson
asked on
How do I bind an array to a listbox?
Greetings Experts...
Disclaimer: Newbie
I've been playing around with writing my own classes and have actually been fairly successful. That being said. I'm trying to use an array as a property in a class. I don't know how to bind the array to a listbox, I don't even know if I declared the array correctly.
Here's the code in the class
Dim lweekstr As Array = Array.CreateInstance(GetTy pe(Object) , 53)
Public Property weekstr() As Array
Get
Return lweekstr
End Get
Set(ByVal Value As Array)
lweekstr = Value
End Set
End Property
Here's the code in the class that instantiates the above:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim f As New ClassLibrary1.CalendarClas s
f.Year = 2004
f.test() 'this method populates the array
Me.ListBox1.DataSource = f.weekstr
'---- this code tests to see if there is something in the array(there is)
Dim c As Integer
For c = 1 To 10
MsgBox(f.weekstr(c))
Next
End Sub
Thanks in advance for your help
Disclaimer: Newbie
I've been playing around with writing my own classes and have actually been fairly successful. That being said. I'm trying to use an array as a property in a class. I don't know how to bind the array to a listbox, I don't even know if I declared the array correctly.
Here's the code in the class
Dim lweekstr As Array = Array.CreateInstance(GetTy
Public Property weekstr() As Array
Get
Return lweekstr
End Get
Set(ByVal Value As Array)
lweekstr = Value
End Set
End Property
Here's the code in the class that instantiates the above:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim f As New ClassLibrary1.CalendarClas
f.Year = 2004
f.test() 'this method populates the array
Me.ListBox1.DataSource = f.weekstr
'---- this code tests to see if there is something in the array(there is)
Dim c As Integer
For c = 1 To 10
MsgBox(f.weekstr(c))
Next
End Sub
Thanks in advance for your help
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
To bind lb to array
ListBox1.DataSource = (arr)
To ppulate array from lb
ListBox1.Items.CopyTo(arr, 0)
or all together - populate array from lb and back to array
Dim arr(ListBox1.Items.Count - 1)
ListBox1.Items.CopyTo(arr, 0)
ListBox1.Items.Clear()
MessageBox.Show(Join(arr, ";"))
ListBox1.Items.AddRange(ar r)
ListBox1.DataSource = (arr)
To ppulate array from lb
ListBox1.Items.CopyTo(arr,
or all together - populate array from lb and back to array
Dim arr(ListBox1.Items.Count - 1)
ListBox1.Items.CopyTo(arr,
ListBox1.Items.Clear()
MessageBox.Show(Join(arr, ";"))
ListBox1.Items.AddRange(ar
Dim lWeekStr As Integer()
Bob