help me to create an array of controls at runtime

G

Guest

Hi,

I have built a control consisting of two listboxes and a button. The idea is
that I populat ethe list on the left, and the user selects items that are
added to the listbox on the right. This list is exposed by my user control as
an array.

I want to bve able to add multiple controls at runtime (basically one for
each parameter of a stored procedure that the user will select from a
drop-down).

I tried to test this idea having new controls added to an array but I get an
error 'Object reference not set to an instance of an object'

How should I do this in VB.NET please?

here is the code I have:

Dim tb As New TabPage
Dim ls() As ListSelector
Static count As Int16

tabParams.TabPages.Add(tb)
tb.Text = count

Dim listSel As New ListSelector

ls(count) = listSel

tb.Controls.Add(ls(count))

With ls(count)
.DataList = Nothing
.Location = New System.Drawing.Point(16, 8)
.Name = "ListSelector1"
.SelectedList = Nothing
.Size = New System.Drawing.Size(368, 144)
.TabIndex = 0
End With

count = count + 1
 
C

ClayB

If you want ls to dynamically grow, then you probably need to use an
ArrayList (or a Generic List<> if this is available in VB.NET 2.0).

Dim Is As New ArrayList

'....

Is.Add(listSel)

===============================
Clay Burch
Syncfusion, Inc.
 

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