....create a drop down list using vb code.....and add to it the text i want?
:wave:
Printable View
....create a drop down list using vb code.....and add to it the text i want?
:wave:
do you mean create a combobox on the fly?
if so, check out this FAQ on loading controls at run-time: http://www.vbforums.com/showthread.php?t=342054
no idea what u want to do really explainQuote:
create a drop down list using vb code
Quote:
Originally Posted by bushmobile
VB Code:
Dim cmdButton(4) As CommandButton Private Sub Form_Load() Dim i As Integer For i = 1 To 4 Load cmdButton(i) With cmdButton(i) .Left = 750 * i .Top = 1000 .Width = 700 .Height = 500 .Caption = "Hello" .Visible = True End With Next i End Sub
error occuring objext variable or with block variable not set what i do
i want to be able to create a dropdown list using the code and not drawing it from the toolbox.and i want to add items on it. for example by pressing the button i create a dropdown list in the picturebox and in it i have numbers(1-30) .
Thx
Have a look at the link I posted - that's what that is all about.Quote:
Originally Posted by panais
@shakti:
You're mixing and matching the methods.
This should be used with:VB Code:
Dim cmdButton(4) As CommandButtonVB Code:
Set cmdButton(i) = Me.Controls.Add("VB.CommandButton", "cmdButton" & Me.Controls.Count)
To useyou have to put a commandbutton on your form (make it invisible if you like), name it correctly and set the index to 0. you don't make a declaration of any commandbutton objects, you just load new members of the current array.VB Code:
Load cmdButton(i)
ok thanks
Why do you need to do it in code when it is already created for you? As they say "Do not re-invent the wheel"
use can also use this one
draw a drop down list
and use a combo and make it style as drop down list
VB Code:
Private Sub Form_Load() Combo1.Visible = False End Sub
and visible true where u want to create the drop down list
VB Code:
Set cmdButton(i) = Me.Controls.Add("VB.CommandButton", "cmdButton" & Me.Controls.Count)
bush where i use this code on form load??
you use it in whatever event you want to create the control.
Read the first two posts of the link, it's all in there
The reason i want to do this through code.....is that i am creating a dynamic map program.I load a map in the picturebox and i draw some shapes on it.In those shapes i want to add a dropdown list to add data in it and afterwards i will connect it with a database.So as u can see i must create the list through code.
Quote:
Originally Posted by bushmobile
VB Code:
Dim WithEvents cmdButton As CommandButton Private Sub cmdButton_Click() MsgBox "hi" End Sub Private Sub Form_Load() Set cmdButton = Form1.Controls.Add"VB.CommandButton", "newCommandButton" ) With cmbButton .Left = 1000 .Top = 1000 .Width = 2000 .Height = 500 .Caption = "Hello" .Visible = True End With End Sub Private Sub Form_Unload(Cancel As Integer) Set cmdButton = Nothing End Sub
Is this the code u are suggesting to use?Where do i write dropdown_list or something like that?I do not really understantto be honest.i have to try it.
Thx anyway.
I'm assuming that by DropDown list you mean ComboBox:VB Code:
Private WithEvents cboCombo As ComboBox Private Sub Form_Load() Set cboCombo = Form1.Controls.Add("VB.ComboBox", "cboBox" ) With cboCombo .Left = 1000 .Top = 1000 .Width = 2000 .Style = 2 .AddItem "TEST" .Visible = True End With End Sub Private Sub cboCombo_Click() MsgBox List1.List(List1.ListIndex) End Sub Private Sub Form_Unload(Cancel As Integer) Set cboCombo = Nothing End Sub