Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Visual Basic (Microsoft) Versions 5/6 FAQ

What VB shoud be able to do!

ComboBox Style=2 shows title once..... by unborn
Posted: 29 Jun 02

ok check this out... with a combo box you have 3 styles... 2 of these are dropdown and the 3rd is a nondrop down.. well im focusing on style 2 here the style that is a dropdown but you are NOT allowed to write in it.. but yes have text shown on it when it loads up.. example of why you would want to use this code?

perhaps you want a pull down box with "Chose State" or something and once they chose something "Chose State" will no longer be available... well here we go..

'put in combo click propertie
Private Sub Combo1_Click()
Static once 'makes it so the value will stay the same until change again.

If once <> "yes" Then 'checks if once has been activated.
    If Combo1.Text <> "Enter Name" Then 'checks if the text is the same text you only wanna display once.
        Combo1.RemoveItem (0) 'if so it removes it.
        once = "yes" 'sets once to tell it has run already this way it doesnt delete the first thing in the box every time the box is pulled down.
    End If
End If

End Sub

'put in form load
Private Sub Form_Load()
With Combo1 'adds sample stuff.
        .AddItem "Enter Name"
        .AddItem "line1"
        .AddItem "line2"
        .AddItem "line3"
        .AddItem "line4"
        .AddItem "line5"
End With

Combo1.ListIndex = 0 'makes it so the text you want to show is selected when program is ran.

'note is is important that the thing you want to be deleted is the first thing in the list.. if not.. then you listindex's need to be changed to the index number it is.

End Sub

and that is how i do it.. hope you people enjoy my first FAQ!!

Back to Visual Basic (Microsoft) Versions 5/6 FAQ Index
Back to Visual Basic (Microsoft) Versions 5/6 Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close