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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with ComboBox 2

Status
Not open for further replies.

Ferlin

Programmer
Jan 18, 2001
71
US
Hi All,

I have ComboBox in an application that has a Description showing in the Dropdown List. Each description has an Code that goes with it. Such as:

Code: 53EB1
Description: Engineering Assistant Grade 1

What I have done so far is to place the code in the tag property of the ComboBox when the user clicks on that choice from the dropdown, that code works fine.

What I want to do next is to find a way to place that code in the ComboBox on the form, but not in the dropdown list, and just set the caption property of a label next to it equal to that description. So the user see's the code in the ComboBox and the description in the label.

Problem is I also don't want them to be able to key in the ComboBox, there for I have set the style to 2, so the text property is READONLY, so I can't set it to the code.

Any suggestions on how I might accomplish this?

Any help would be greatly appreciated.

Respectfully:

Ferlin.
 
The way I solved a similar problem was to make the style - 0 to set the Combo1.Text. True, you don't want them to be able to key in any text, but if you set the Combo's text and the Label's caption in the Combo's click event, that can be a way around that:
------------------------------------
Private Sub Combo1_Click()
If Combo1.Text = "" Then Exit Sub

Label1.Caption = Combo1.Text
Combo1.Text = Combo1.Tag
End Sub
------------------------------------

Since the Click event is only called when the user selects an item from the drop down list, this forces that code to be run wheather they key in a value or not. You can make extra sure they selected an item by checking if Combo1.ListIndex >= 0. Play with this code some to make sure it will suit your needs, but I haven't seen any holes in it yet, especially if you check the ListIndex before moving on.

Hope that helps!

~Mike
Any man willing to sacrifice liberty for security deserves neither liberty nor security.

-Ben Franklin
 
I have tried to do that before, and i solved by not letting the user write anything on the combo box, just clikcing on it.

i used

Private sub combo1_Keypress(Dim ascci as int)
ascci=0
end sub


this makes it so that doesnt matter what the user types, it wont let him write anything on the combobox.text


i dont have the exact code here with me right now, but i hope it helps

Eli
 
MikeCox and elibb,

I found the best solution to my problem, in conjunction with the rest of the code in my application was to use BOTH suggestions together. The keypress event setting keyascii=0 and the text=tag properties in the click event. Thanks to both of you for your help, was VERY usefull.

In thanks, I'll give you both a helpful post vote.

Ferlin.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top