|
-
January 24th, 2000, 07:53 PM
#1
Help with Combo boxes
I need a little help..
I have a table with
Number Name
1 James
2 Bill
3 Sam
I am tryin to display the number only in the combobox.. Put I want the the Number and name to display when you click on the arrow.
I know you can do this in Access.
But is there a way to do this in VB.
Thanks
-
January 25th, 2000, 02:06 PM
#2
Re: Help with Combo boxes
I don't know of any easy way to do this, but you could do something like the following...
Populate the list with the number and name for each record.
Then while you're building the list, each time you add one, add a value to the itemdata property - this only holds numbers.
ie.
(if you're pulling these values from a database...)
cboNumber.AddItem rs!Number & " " & rs!Name
cboNumber.Itemdata(cboNumber.NewIndex) = rs!Number
You'll have to use another control to hold this value because once you change the text in the combo box, it tries to match it with something is has in the list, and when it doesn't find an entry for 2 or 3 it will reset the listindex to -1 and that text will be gone. So if you need this value (which i assume that you do) you'll have to place it somewhere else, like a label or a text box.
Then in the click event, change the text of the value holding control to the combo box's itemdata value(only the number).
ie.
txtNumber.Text = cboNumber.ItemData(cboNumber.ListIndex)
hope this helps,
John
John Pirkey
MCSD
www.ShallowWaterSystems.com
John Pirkey
MCSD (VB6)
http://www.stlvbug.org
-
January 25th, 2000, 11:50 PM
#3
Re: Help with Combo boxes
Thanks Johnny,
That Helped alot
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|