|
-
May 31st, 2006, 01:54 AM
#1
Thread Starter
Lively Member
How can I...?
....create a drop down list using vb code.....and add to it the text i want?
-
May 31st, 2006, 01:58 AM
#2
Re: How can I...?
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
-
May 31st, 2006, 02:03 AM
#3
Re: How can I...?
create a drop down list using vb code
no idea what u want to do really explain
-
May 31st, 2006, 02:11 AM
#4
Re: How can I...?
 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
-
May 31st, 2006, 02:16 AM
#5
Thread Starter
Lively Member
Re: How can I...?
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
-
May 31st, 2006, 02:21 AM
#6
Re: How can I...?
 Originally Posted by panais
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)
Have a look at the link I posted - that's what that is all about.
@shakti:
You're mixing and matching the methods.
VB Code:
Dim cmdButton(4) As CommandButton
This should be used with:
VB Code:
Set cmdButton(i) = Me.Controls.Add("VB.CommandButton", "cmdButton" & Me.Controls.Count)
To use you 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.
-
May 31st, 2006, 02:23 AM
#7
Thread Starter
Lively Member
-
May 31st, 2006, 02:24 AM
#8
PowerPoster
Re: How can I...?
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"
-
May 31st, 2006, 02:27 AM
#9
Re: How can I...?
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
-
May 31st, 2006, 02:29 AM
#10
Re: How can I...?
VB Code:
Set cmdButton(i) = Me.Controls.Add("VB.CommandButton", "cmdButton" & Me.Controls.Count)
bush where i use this code on form load??
-
May 31st, 2006, 02:32 AM
#11
Re: How can I...?
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
-
May 31st, 2006, 02:33 AM
#12
Thread Starter
Lively Member
Re: How can I...?
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.
-
May 31st, 2006, 02:51 AM
#13
Thread Starter
Lively Member
Re: How can I...?
 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.
-
May 31st, 2006, 02:55 AM
#14
Re: How can I...?
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|