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

Display something other than bound column in combobox

Status
Not open for further replies.

mdav2

Programmer
Aug 22, 2000
363
GB
Basically I have a combobox with 2 columns based on a table:

Field Data
===========================
nID primary key (number)
cDescpt text field with description

NID CDESCRPT
===========================
1 Joe Blogss
2 Dave Jones
3 Michael Jackson

I want to record the NID field as the bound column BUT show CDESCRPT as "text" in the combo box when an item is selected.

For example,

I select 2, Dave Jones from the list and the combo box shows the value "2". I want it to show "Dave Jones" BUT retain the 2 as the actual value for the combobox.

I can't find anyway to do this and my only work around has been to create a textbox and set the value of that to the CDESCRPT value after the user has made a selection. Is there an easier way tan doing this?

Mark Davies
Warwickshire County Council
 
Turn it around so that the name comes first.

Use a query as the source for the combo:
[TT]
Select CDescrpt, NID From ....
[/TT]

Then alter the combo properties
[TT]
ColumnCount = 2
BoundColumn = 2
[/TT]
This way you'll show the name but select the number.

The number will appear in the dropdown. You can hide it by setting ColumnWidth to something like 100, 0.

BTW, I'm not many miles from you so if it's my Council Tax you're doing - just drop my name from the list will you.



Geoff Franklin
 
If I had control of the council tax I would remove my own name as well ;-)

Will give that a go and see how I get on. Thanks for the help Geoff.

Mark Davies
Warwickshire County Council
 
>>I want to record the NID field as the bound column BUT show CDESCRPT as "text" in the combo box when an item is selected.

A combo box always shows the content of Column 1 when it is in the closed position and there is no way to alter that. So the only solution is, as Geoff said, to reverse the order of the data so that the description is first, and the ID second (don't forget to set the BoundColumn = 2).
You can then also suppress the display of the ID by setting the ColumnWidths property to something like "213,0" (it is a string) so that only the description is visible when the combo is dropped down too.

----
Andy Kramek
Visual FoxPro MVP
 
Geoff that did work a treat and after you said it I was sure I had done this in another project somewhere (just don't get enough development time).

Thanks,

Mark Davies
Warwickshire County Council
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top