Array of structures

L

LR

Is it possible to use an array of structures as a datasource for a control.

ie

dim structure structtest
dim str1 as string
dim str2 as string
end structure

dim artest() as structtest

how do I use the array as a data source for a list box?
 
I

Imran Koradia

Here's how you can go about this:

Public Structure DataStructure
Private s As String
Public Property Str() As String
Get
Return s
End Get
Set(ByVal Value As String)
s = Value
End Set
End Property
End Structure

Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim o(2) As DataStructure
o(0) = New DataStructure
o(0).Str = "Item 1"
o(1) = New DataStructure
o(1).Str = "Item 2"
o(2) = New DataStructure
o(2).Str = "Item 3"
ListBox1.DataSource = o
ListBox1.DisplayMember = "Str"
End Sub


hope that helps..
Imran.
 
G

Guest

You can use a class instead of a data structure then bind either an arraylist
or array of the classes to controls like the DataGrid.
 

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