Results 1 to 14 of 14

Thread: How can I...?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Posts
    100

    How can I...?

    ....create a drop down list using vb code.....and add to it the text i want?


  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    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

  3. #3
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: How can I...?

    create a drop down list using vb code
    no idea what u want to do really explain

  4. #4
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: How can I...?

    Quote Originally Posted by bushmobile
    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
    VB Code:
    1. Dim cmdButton(4) As CommandButton
    2. Private Sub Form_Load()
    3.     Dim i As Integer
    4.     For i = 1 To 4
    5.         Load cmdButton(i)
    6.         With cmdButton(i)
    7.             .Left = 750 * i
    8.             .Top = 1000
    9.             .Width = 700
    10.             .Height = 500
    11.             .Caption = "Hello"
    12.             .Visible = True
    13.         End With
    14.     Next i
    15. End Sub

    error occuring objext variable or with block variable not set what i do

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Posts
    100

    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

  6. #6
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: How can I...?

    Quote 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:
    1. Dim cmdButton(4) As CommandButton
    This should be used with:
    VB Code:
    1. Set cmdButton(i) = Me.Controls.Add("VB.CommandButton", "cmdButton" & Me.Controls.Count)

    To use
    VB Code:
    1. Load cmdButton(i)
    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.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Posts
    100

    Re: How can I...?

    ok thanks

  8. #8
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    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"
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  9. #9
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    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:
    1. Private Sub Form_Load()
    2. Combo1.Visible = False
    3. End Sub

    and visible true where u want to create the drop down list

  10. #10
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: How can I...?

    VB Code:
    1. Set cmdButton(i) = Me.Controls.Add("VB.CommandButton", "cmdButton" & Me.Controls.Count)

    bush where i use this code on form load??

  11. #11
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    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

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Posts
    100

    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.

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Posts
    100

    Re: How can I...?

    Quote Originally Posted by bushmobile
    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

    VB Code:
    1. Dim WithEvents cmdButton As CommandButton
    2.  
    3. Private Sub cmdButton_Click()
    4.      MsgBox "hi"
    5. End Sub
    6.  
    7.  
    8. Private Sub Form_Load()
    9.  
    10.     Set cmdButton = Form1.Controls.Add"VB.CommandButton", "newCommandButton" )
    11.      
    12.     With cmbButton
    13.         .Left = 1000
    14.         .Top = 1000
    15.         .Width = 2000
    16.         .Height = 500
    17.         .Caption = "Hello"
    18.         .Visible = True
    19.      End With
    20.  
    21. End Sub
    22.  
    23. Private Sub Form_Unload(Cancel As Integer)
    24.     Set cmdButton = Nothing
    25. 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.

  14. #14
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: How can I...?

    I'm assuming that by DropDown list you mean ComboBox:
    VB Code:
    1. Private WithEvents cboCombo As ComboBox
    2.  
    3. Private Sub Form_Load()
    4.  
    5.     Set cboCombo = Form1.Controls.Add("VB.ComboBox", "cboBox" )
    6.      
    7.     With cboCombo
    8.         .Left = 1000
    9.         .Top = 1000
    10.         .Width = 2000
    11.         .Style = 2
    12.         .AddItem "TEST"
    13.         .Visible = True
    14.      End With
    15. End Sub
    16.  
    17. Private Sub cboCombo_Click()
    18.     MsgBox List1.List(List1.ListIndex)
    19. End Sub
    20.  
    21. Private Sub Form_Unload(Cancel As Integer)
    22.     Set cboCombo = Nothing
    23. 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
  •  



Click Here to Expand Forum to Full Width