Link to home
Start Free TrialLog in
Avatar of hlominac
hlominac

asked on

Display comboxes created at runtime

I am generating comboboxes as:
 Public Combos() As ComboBox
later I use:
 ReDim Combos(5)
      For J = 0 To 5
         Combos(J) = New ComboBox
      Next
I use Combos(0).Items.Add(Item) for example to populate them.
However I cannot display the comboboxes on the form.
What is missing?
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

You still need to place them somewhere on the form (through coding)

Example:

For J = 0 To 5
         ComboBox x = New ComboBox
         x.Size = New System.Drawing.Size(60, 15)  
         x.Location = New System.Drawing.Point(30 * J, 200)  
         Me.Controls.Add(x)  
         Combos(J) = x
      Next


http://www.dreamincode.net/forums/topic/63445-dynamic-form-and-controls-generation/
This Article may help you in creating dynamic combobox in windows form:-

http://aspalliance.com/1385_Building_Dynamic_NET_Controls_with_Windows_Forms.2
Avatar of hlominac
hlominac

ASKER

Dhaest:,
When I ran your code I got an error message at: Me.Controls.Add(x)  
Controls is not a member of MyProgram.Data where Data is the subroutine containing the code.
How do I declare Controls?
Harold
ASKER CERTIFIED SOLUTION
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Using your example I learned a lot about creating in runtime.  Thank you!