Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating Listboxes "on the fly"

Status
Not open for further replies.

vonehle

Programmer
May 16, 2006
35
US
Let's say I ask the user for a number between 1 and 10, then they click a button. How would I then create that same number of listboxes to appear on a form? I know I could create them and make them visible after the number is entered, but I don't want to have to do it that way.
 
One way would be to have a control like a placeholder (not sure if desktop has that) and then create listboxes in code and add them to your placeholder.
 
Try something like (not tested):

[tt]
'Validate that user input is a valid number between 1 and 10
'Result of validation would leave number in an Integer variable called UserInput
'Then ...
For a As Integer = 1 To UserInput
Dim lb As New System.Windows.Forms.ListBox
'Do any required positioning here (ie set lb.Top, lb.Left, lb.Height and lb.Width etc.)
'You might also want to look up using AddHandler if you want the list boxes to respond to events
Me.Controls.Add(lb)
Next
[/tt]

Hopefully this will point you in the right direction.



[vampire][bat]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top