Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ComboBox Style=2 shows title once.....

What VB shoud be able to do!

ComboBox Style=2 shows title once.....

by  unborn  Posted    (Edited  )
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..

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

[color blue]If[/color] once [color blue]<>[/color] "yes" [color blue]Then[/color] [color green]'checks if once has been activated.[/color]
[color blue]If[/color] Combo1.Text [color blue]<>[/color] "Enter Name" [color blue]Then[/color] [color green]'checks if the text is the same text you only wanna display once.[/color]
Combo1.RemoveItem (0) [color green]'if so it removes it.[/color]
once = "yes" [color green]'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.[/color]
[color blue]End If[/color]
[color blue]End If[/color]

[color blue]End Sub[/color]

[color green]'put in form load[/color]
[color blue]Private Sub[/color] Form_Load()

[color blue]With[/color] Combo1 [color green]'adds sample stuff.[/color]
.AddItem "Enter Name"
.AddItem "line1"
.AddItem "line2"
.AddItem "line3"
.AddItem "line4"
.AddItem "line5"
[color blue]End With[/color]

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

[color green]'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. [/color]

[color blue]End Sub[/color]



and that is how i do it.. hope you people enjoy my first FAQ!!
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top