Results 1 to 5 of 5

Thread: very simple... combo boxes

  1. #1
    adamr1001
    Guest

    very simple... combo boxes

    I am a novice, so be kind. lol.

    How do you define the contents of a combo box? and where do you do it?

    If I had the the VB help files or if the search box @ vbworld.com was working, i wouldn't ask an obviously easy question....

    ...so thanks a bunch to anyone who can show me.

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    You could actually add items to a ComboBox during design-time if you like.
    Simply click down the List property type an item and press CTRL+Enter and type the next.
    If you want to do it thru code, which is more common because often you fill it up with information from a file or database, simply use the AddItem method.

    Where you call the AddItem depends when you want to fill the Box but usually in the Form_Load event.
    VB Code:
    1. Private Sub Form_Load()
    2.     Combo1.AddItem "Monday"
    3.     Combo1.AddItem "Tuesday"
    4.     Combo1.AddItem "Wendesday"
    5.     Combo1.AddItem "Thursday"
    6.     Combo1.AddItem "Friday"
    7.     Combo1.AddItem "Saturday"
    8.     Combo1.AddItem "Sunday"
    9.     Combo1.AddItem "Not a fun day"
    10. End Sub
    Best regards

  3. #3
    adamr1001
    Guest
    Thanks Joacim,
    second time tonight you've helped me.
    I have just begun developing an application for my office, voluntaril, with very little VB experience.
    You can expect some more questions in the next couple of days.
    lol. ...and best regards to you. Adam.

  4. #4
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    Hi
    Don't want to go to crazy on a simple post but just to also state that is good idea to clear combo box before filling... Combo1.Clear... and also to set the ListIndex property after filling it with Additem.... Combo1.Listindex = 0 for eg.
    Regards
    Stuart
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  5. #5
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Originally posted by beachbum
    Hi
    Don't want to go to crazy on a simple post but just to also state that is good idea to clear combo box before filling... Combo1.Clear... and also to set the ListIndex property after filling it with Additem.... Combo1.Listindex = 0 for eg.
    Regards
    Stuart
    That's true but if you fill it in the Form_Load event you don't really need to clear it if you haven't set any items during design-time.

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