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

Show two columns in a combobox 1

Status
Not open for further replies.

scklifasovskiy

Programmer
Nov 12, 2012
57
CA
Hi all!
Its been sometime i coded in Fox so forgive me if question is silly.
I have a combo box with three columns --code,description,region.
Bounded column is 1. But I would like to show two columns -- Code and Description but not region.
Can I do it?
 
First, set the combo box's ColumnCount property to 2.

Next, set its RowSourceType tp 6, and its RowSource to "MyTable.Code,Description".

Finally, set its ColumnWidth property to the desired widths (in pixels) of the columns that you want to display, as a comma-delimited list (e.g. "30,100").

I think that should do it.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
After the selection you always only see the first column in the closed combobox.

Therefore it's usually done this way: Define 1 Column more than needed, set Columnwidths = "0, ...other columns", this hides the first column in the dropdown list. In the first column fill in an expression putting together all you want to see after a selection of an item has been made. And rather set the Boundcolumn to any other column, perhaps the last one, which columnwidth you also set 0.

Bye, Olaf.
 
Mike,
I have my combo setup exactly as you suggesting.
But I have three columns and would like to show only first two.
Right now it shows only first one.
 
I have three columns and would like to show only first two

But, if you had set it up as I indicated, you would only have two columns. The number of columns is defined by the RowSource ("MyTable.Code,Description") and the ColumnCount (2). Where does the third column come from?

I suggest you double-check your settings, and see where they are different from mine.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Olaf,
I absolutely need to show first two columns with first one to be bounded. Cannot play with clients display needs.
 
Mike,
I understand that I am not clear.
In a closed combo -- I need to see two columns
In a open combo -- I need to see three columns
Is it possible?
 
In a closed combo -- I need to see two columns

That's not what you originally said. You simply said you wanted to see two columns. You didn't say you wanted to see something different in a closed and open combo.

In short, the combo only shows one column when in its closed state. You can't vary that by juggling the properties.

The only workaround I can think of would be to create a cursor in which the first field contains a combination of Code and Description, that is, it contains those two fields concatenated together. The second field would be Region. Then set the ColumnCount to 2. That would do it, but it would look ugly (because the Description wouldn't line up properly [unless you used a fixed-pitch font, which would probably look even worse]).

Mike




__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
great idea mike!
but can be more specific how two change properties to work with this cursor?
my cursor is something like this:
Select PADR(Code,20)+", "+PADR(Description,150) AS Desc,;
Region,;
Code;
FROM bank;
INTO CURSOR csr1
And I would like to bound 3rd column.
 
OK, you're on the right track. The next step is to set the RecordSourceType to 6 and the RecordSource to "csr1.Desc,Region,Code". Finally, set the BoundColumn to 3.

The only trouble is that you will see the Code twice: once in the concatenated field, and once on its own. To get round that, set the width of the third column to zero. So ColumnWidth would contain something like "30,100,0".

One other small point: PADR(Code,20)+", "+PADR(Description,150) will result in the comma appearing immediately after a string of spaces, and immediately before the description. That's probably not what you want. Either leaver out the comma, or wrap the PADR() around the entire field, rather than each of the two components:

PADR(ALLTRIM(Code) +", "+Description, 170)

You might need to play around with that to get the best result.

Mike





__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
>I absolutely need to show first two columns with first one to be bounded.
Concatenating the first two columns into one will fulfill your clients needs. You don't have to stick to the specs on the description level, the customer will be satisifed with visually seeing what he wants, it doesn't matter how the technical solution is. You're even forced to concat the first two colums, as I said the combobox doesn't display two columns collapsed, only expanded. There is no other solution than to concat what you need to show in one display column.

So you put in a rowsourcetype of SQL-Select and Select field1+field2 as cbocolumn1, field1, field2 and set boundcolumn=2, columncount = 3 and columnwidths = 0,100,100.
I see you're going in that direction anyway.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top