×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

how to set what a combobox displays in the textbox area

how to set what a combobox displays in the textbox area

how to set what a combobox displays in the textbox area

(OP)
hello,

I have a combobox that is used to select a guest from a table of guests

some of the properties of the combo:
boundcolumn=.3
boundto=.t.
rowsource = guest.last, first, g_no
rowsourcetype = 6 fields

the combo works fine

my problem is that when i select from the dropdown list then in the textbox portion of the combo only lastname is displayed.
is there a way to display both last and first?

RE: how to set what a combobox displays in the textbox area

Yes. First, set .ColumnCount to 2. That will display the first two columns (guest.last and guest.first, in this case).

The problem is that the columns will be "ragged", which is the result of using proportional fonts. (If you don't understand the reason for this, just try it for yourself.) To cure that, you could use a fixed-pitch font such as Courier New, but most people consider that ugly.

An alternative solution is to set the colum widths to specific values. To do that, set .ColumnWidth to a comma-delimited list of the desired values. For example, .ColumnWidth = "30,25". You will have to experiment to get the best values for your data.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: how to set what a combobox displays in the textbox area

The textbox portion is always displaying the first field only, so make that an expression you need. You can't only use pure fields with rowsourcetype fields.

If you go for the northwind employees table with lastname, firstname, employeeid - you can set a combobox to this

BoundColumn = 4
ColumnCount = 4
ColumnWidths = "0,100,100,0" && what columns you see in the expanded items list from which you pick
RowSourceType = 6
RowSource = "lastname-(', '+firstname), lastname, firstname, employeeid"
ControlSource = "employees"
Width = 200
BoundTo = .T. 

Collapsed, a combobox always displays column 1 of the fields, so to show the full name that's the expression lastname-(', '+firstname). If you don't know what minus does in string concatenation look it up in the help. In short, this results in displaying "Lastname, Firstname"

In the expanded items list, the columnwidth property determines which width the columns listed have. You could also just show Column 1 there, but a better layout is the two separated name part columns - each in its own left-aligned column. That's columns 2 and 3, thus you don't want to see column 1 (the lastname,firstname epression) and column 4 (the employeeid number) and use columnwidths="0,100,100,0" to make columns 1 and 4 disappear in the item list.

I don't know from the top of my head how you can get the dropdown list width right. In my tests, the dropdown list width didn't align with the combobox width, but that should be possible.

Chriss

RE: how to set what a combobox displays in the textbox area

Oops. Sorry, I didn't read your question carefully. I thought you wanted to display both parts of the name in the drop-down portion. In fact, you want them to appear in the textbox portion.

No, as far as I know that's not possible. The best I can suggest is that you combine the two fields into a single field, and use that as your RowSource. But that is probably now what you want.

I'll leave my previous answer in place for the benefit of anyone who wants to know how to display multiple columns in the drop-down portion of a combo.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: how to set what a combobox displays in the textbox area

Hi
You may want to have a look at DISPLAYVALUE (see code below)

CODE -->

PUBLIC oForm1

oform1=NEWOBJECT("form1")
oForm1.Visible = .T.
oform1.Show

READ Events

CLOSE ALL
CLEAR ALL 

RETURN

**********

DEFINE CLASS form1 AS form
Height = 240
Width = 360
Autocenter = .T.
Borderstyle = 2
MinButton = .F.
MaxButton = .F.
Themes = .F.
ShowTips = .T.

	ADD OBJECT cboChooseGuest as ComboBox WITH ;
		Style = 0, ;
		Top = 60, ;
		Left = 12, ;
		Width = 300, ;
		RowSourceType = 6, ;
		RowSource = "Guests.LastName, FirstName, G_No", ;
		BoundTo = .T., ;
		BoundColumn = 3, ;
		ColumnCount = 3, ;
		ColumnWidths = "120, 120, 30, 0"
		
		PROCEDURE cboChooseGuest.InterActiveChange()
			WITH This
				.DisplayValue = ALLTRIM(This.List[This.ListIndex, 1]) + " - " + ALLTRIM(This.List[This.Listindex, 2]) + " - " + ALLTRIM(This.List[This.Listindex, 3])
				.Refresh()
			ENDWITH 
		ENDPROC

	PROCEDURE Load
		CREATE CURSOR Guests (LastName C(48), FirstName C(48), G_No C(3))
		INSERT INTO Guests values("Meyer", "Goerge", "1")
		INSERT INTO Guests values("Bogart", "Humphrey", "2")
		INSERT INTO Guests values("Hepburn", "Katherine", "3")
		INSERT INTO Guests values("Cluny", "Goerge", "4")
ENDPROC

	PROCEDURE Destroy
		CLEAR EVENTS

	ENDPROC 

ENDDEFINE

********** 

hth

MarK



RE: how to set what a combobox displays in the textbox area

I won't decide what's better, not because I'm biased towards my solution. In both cases you need to compute what you want to be displayed. In MarKs solution the fields rowsourecetype keeps at just being fields but you need code in an event in my case the rowsource expression is interpreting the rowsource type "fields" very loosely.

I personally struggle to get MarKs idea working for my combobox in a visual form, it works flawless as his PRG code. But I likely have overlooked a detail to also set correctly. I checked if the key column has to be char and not numeric, but you can also adapt MarKs example to an integer G_No column, though there is something differing with boundto=.t. or .f. comboboxes and integer vs char columns used as boundcolumn. I always forget the reasoning behind that, even when reading the description of boundto in the help. In the end, no matter what the details are, you can get the picked item by knowing it becomes the currently selected record in the rowsource alias.

Chriss

RE: how to set what a combobox displays in the textbox area

(OP)
actually Criss solution worked fine

and I omitted some columns as they are not needed

BoundColumn = 2
ColumnCount = 2
ColumnWidths = "231,0"
RowSourceType = 6
RowSource = "guest.lastname-(', '+guest.firstname), employeeid"
BoundTo = .T.
ColumnLines = .f.

thank you all for the info

RE: how to set what a combobox displays in the textbox area

...

and a demo with Chriss's suggestion

CODE -->

PUBLIC oForm1

oform1=NEWOBJECT("form1")
oForm1.Visible = .T.
oform1.Show

READ Events

CLOSE ALL
CLEAR ALL 

RETURN

**********

DEFINE CLASS form1 AS form
Height = 240
Width = 360
Autocenter = .T.
Borderstyle = 2
MinButton = .F.
MaxButton = .F.
Themes = .F.
ShowTips = .T.

	ADD OBJECT lblLName as Label WITH ;
		Top = 24, ;
		Left = 24, ;
		Caption = "Lastname"
	
	ADD OBJECT lblFName as Label WITH ;
		Top = 24, ;
		Left = 24 + 90 + 12, ;
		Caption = "Firstname"
	
	ADD OBJECT lblGNumber as Label WITH ;
		Top = 24, ;
		Left = 24 + 90 + 12 + 90 + 12, ;
		Caption = "Guest"
	
	ADD OBJECT lblRNumber as Label WITH ;
		Top = 24, ;
		Left = 24 + 90 + 12 + 90 + 12 + 60, ;
		Caption = "Room"
	

	ADD OBJECT txtLName as TextBox WITH ;
		Top = 48, ;
		Left = 24, ;
		Width = 90, ;
		ControlSource = "Guests.LastName", ;
		ReadOnly = .T., ;
		DisabledBackColor = RGB(0, 240, 240)

	ADD OBJECT txtFName as TextBox WITH ;
		Top = 48, ;
		Left = 24 + 90 + 12, ;
		Width = 90, ;
		ControlSource = "Guests.FirstName", ;
		ReadOnly = .T., ;
		DisabledBackColor = RGB(0, 240, 240)
		
	ADD OBJECT txtGNumber as TextBox WITH ;
		Top = 48, ;
		Left = 126 + 90 + 12, ;
		Width = 48, ;
		ControlSource = "Guests.G_No", ;
		ReadOnly = .T., ;
		DisabledBackColor = RGB(0, 240, 240)

	ADD OBJECT txtRNumber as TextBox WITH ;
		Top = 48, ;
		Left = 126 + 90 + 12 + 48 + 12, ;
		Width = 48, ;
		Alignment = 1, ;
		ControlSource = "Guests.R_No", ;
		ReadOnly = .T., ;
		DisabledBackColor = RGB(0, 240, 240)
		

	ADD OBJECT cboChooseGuest as ComboBox WITH ;
		Style = 2, ;
		Top = 90, ;
		Left = 24, ;
		Width = 312, ;
		BoundColumn = 4, ;
		ColumnCount = 4, ;
		ColumnWidths = "0,138,138,0", ;
		RowSourceType = 6, ;
		RowSource = "Guests.lastname-(', '+firstname-(', ' + ALLTRIM(STR(G_No)))), lastname, firstname, G_No", ;
		ControlSource = "Guests", ;
		BoundTo = .T. 
		IncrementalSearch = .T.

		PROCEDURE cboChooseGuest.Click()
			ThisForm.txtLName.SetFocus()
			Thisform.Refresh()

		ENDPROC 

	PROCEDURE Load
		CREATE CURSOR Guests (LastName C(48), FirstName C(48), G_No I , R_No C(3))
		
		INSERT INTO Guests values("Meyer", "Jeffrey", 1, "15")
		INSERT INTO Guests values("Bogart", "Humphrey", 22, "17")
		INSERT INTO Guests values("Hepburn", "Katherine", 3, "223")
		INSERT INTO Guests values("Clooney", "Goerge", 4, "545")
		INSERT INTO Guests values("Miller", "Chris", 5, "54")
		INSERT INTO Guests values("Lewis", "Mike", 26, "11")
		INSERT INTO Guests values("Fisher", "Jenny", 16, "121")
		
		LOCATE 

	ENDPROC 

	PROCEDURE Destroy
		CLEAR EVENTS

	ENDPROC 

ENDDEFINE

********** 

RE: how to set what a combobox displays in the textbox area

Hi Chris

Quote (Chriss)


I checked if the key column has to be char and not numeric, ...

Does not seems to be crucial anymore - at least if you work with VFP 9

from Hacker's Guide to VFP 7

Quote:


The behavior of lists and combos with numeric data confuses people. The key point is that, even when we think we're seeing numbers in a combo or list, we're actually seeing characters. Combos and lists cannot show numeric data. If you specify a RowSource that's numeric, FoxPro internally converts the data to character before displaying it.

The Value of a list or combo (and, therefore, the ControlSource it's bound to) can be either character or numeric. If the Value is character, it contains the text of the currently highlighted item. If the Value is numeric, by default it contains the index of that item. Before VFP 5, there was no way to get numeric data out of a list or combo. The BoundTo property lets you tell VFP to convert a numeric character string to a number before sticking it into Value or DisplayValue.

hth

MarK

RE: how to set what a combobox displays in the textbox area

I know Hacker's guide is usually enlightening in such things.

But take this:

Quote (Hacker's guide)

The BoundTo property lets you tell VFP to convert a numeric character string to a number before sticking it into Value or DisplayValue.
I see the value becoming the string of an integer id, no matter if I set boundto=.T. or .F.

It's not more than an annoyance as you can always read the actual numeric ID from the table you bound to the combobox, there never is much value in the value of a control anyway, if you bind it to something, you know the source of that value and the source has the original value, so once you use bound controls the controls are only there for diplaying things to the user and the user will not be able to distinguish a string of a number to a number, as a binary nummber also when sticking to the datatype number when bound to, say, a textbox, is always cconverted from the bytes it is to a string of a number. there are just slight hints in case of a textbox, for example, whether the number is aligned right or not.

The essence off what I keep in mind is as long as you get controls to show what you want them to show and to update the tables they're bound to as you want, the goal is achieved and I'd then always read my data from the data - from the tables - not from a control.value anyway. So I'll not be affected by this.

The boundto of a combobox becomes more important, if you also use the combobox.controlsource and the picked item from the rowsource sets the controlsource. In a normalized design you want the primary key of a list of items you display for selection to be stored into a foreign key field, while displayvalue should be something that correspoonds to the key, like a fullname of a person, a productname or anything the key stands for. That's the "holy grail" usage of a combobox, perhaps, editing a foreign key field without the user to need to make the translation from keys to what they stand for.

Chriss

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close