bzg0by
January 24th, 2000, 06:53 PM
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
Johnny101
January 25th, 2000, 01:06 PM
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
bzg0by
January 25th, 2000, 10:50 PM
Thanks Johnny,
That Helped alot