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

Combo box - displaying data not in list

Status
Not open for further replies.

cjac

Programmer
Dec 8, 2003
93
GB
Hi, I don't know if this is possible but is there any way to display data at the side of a focussed row within a combo box? ie. I have a code and a price to display in the list although I don't want the price to appear unless the row has focus. I hope this makes sense as it's pretty difficult to put into words what I actually want. I basically want to just have the codes in the list and then list the price next to the code only when the code is highlighted?

Any pointers much appreciated. Thanks for reading.
Cheers.
CJ
 
Use another combobox and associate the two:


Private Sub Combo1_Click()

Combo2.listindex = Combo1.listindex

End Sub

beware of sorting...
 
Another way is ItemData property. You can assign a numeric value to each row of combo by using ItemData property. And then use it in your code, For example you have combo1:

Combo1.AddItem "Product 1"
Combo1.ItemData(0) = 1200

Combo1.AddItem "Product 2"
Combo1.ItemData(1) = 1500

...


 
However with the itemdata property you can only be assigned an integer. Seldom does a price round to the nearest whole dollar. I agree however that the item data property has its uses.

Matt
 
cjac,

In the project, set reference to Scripting Run time library,
put timer and combo box at the form and copy this code:

Option Explicit

Private mdctMyDictionary As New Scripting.Dictionary

Private Sub Combo1_GotFocus()
Timer1.Enabled = True
End Sub

Private Sub Combo1_Validate(Cancel As Boolean)
Timer1.Enabled = False
End Sub

Private Sub Form_Load()
With Combo1
.AddItem "A"
.AddItem "B"
.AddItem "C"
.AddItem "D"
.AddItem "E"
End With

Timer1.Interval = 250

With mdctMyDictionary
.Add "A", "My Key for A"
.Add "B", "My Key for B"
.Add "C", "My Key for C"
.Add "D", "My Key for D"
.Add "E", "My Key for E"
End With
End Sub

Private Sub Timer1_Timer()
Me.Caption = Combo1.List(Combo1.ListIndex) & " " & _
mdctMyDictionary.Item(Combo1.List(Combo1.ListIndex))
End Sub

VladK
 
Hi

Has anyone ever tried this:

1. convert the price to cents only(multiply by 100)
2. then convert price(in cents) to integer
3. insert this integer into its relevant ItemData slot
4. Place TextBox or Label next to ComboBox
5. on selection of Item in ComboBox
a. Divide ItemData by 100 and format as currency
b. display in TextBox or Label.


I have only played with this a bit but it seems to work.

HTH
Bob


Daughters are Gods Vengeance on Fathers for being Men.
 
tudogs,

Your suggestion should work for the numeric values. I would suggest to look at this problem a bit wider. How to display any (even not numeric) relevent to the highlighted list item information? Look at the example provided in my previous post. It illustrates the technique that tries to solve this problem. That example also tries to identify the highlighted item on hover (while scrolling the drop-down part of the combo box). I believe that what cjac is asking for.

Vladk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top