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

Listbox - Problem (2 3

Status
Not open for further replies.

german12

Programmer
Nov 12, 2001
563
DE
I have a problem with a list box.
The table / grid contains surname and first name in 2 columns.

See image below (right half).

I need both items in the list box (last name and first name = in german "Nachname" and "Vorname") because there are several first names for one last name.
At first I tried 2 columns in a list box, but the formatting in the list box looked awful.
Then I coded as row-source:
Select alltrim (last name) + "," + alltrim (first name) from mydatei into cursor temp.
The result is the left half of the picture.
But I'm not really satisfied.
Actually, I want it to look the same in the list box as it does in the table / cursor.
How do you do this?

Thanks Klaus

Listboxproblem_rnzptt.png



Peace worldwide - it starts here...
 
Hi

Please have a look at the code below. I usually use number of columns = number of displayed fields + 1 and set the last column's width to 0 (zero) in order to have the shown area finish with a v-line.

Code:
...
RowSourceType = 6 && tblYourTable
RowSource = "tblYourTable.cLastName, cFirstName" && 2 fields
ColumnCount = 3 && Number of columns
ColumnWidths = "120, 120, 0" && Width of Columns
BoundColumn = 1
...

Please do also have a look at the attached prg file.

hth

MarK
 
 https://files.engineering.com/getfile.aspx?folder=049146f3-f27f-4381-a3f2-91045f612fc2&file=testlistbox4.prg
Hi Klaus,

The secret to getting the columns to line up correctly is to use the listbox's [tt]ColumnWidths[/tt] property. Set it to a string that contains a comma-delimited list of the desired column widths. So if you expect the Nachname to be, say,15 characters and the Vorname to be 12 characters, you would set the proptery to [tt]"15,12"[/tt].

On another point, you said that you tried this:

[tt]Select alltrim (last name) + "," + alltrim (first name) from mydatei into cursor temp[/tt]

The problem there is that the width of Mydate1 in the cursor will be the width of the full name in the first record. Any longer names will be truncated. To avoid that problem, you need to make sure the full name occupies the same width in all the records:

[tt]SELECT PADR(ALLTRIM(lastname) + " " + ALLTRIM(firstname) , 27)... etc[/tt].

This is not directly relevant to the above solution, but it is something to keep in mind.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi, Mark and Mike
Thank you for the two valuable solutions/hints.
The list looks a lot better now.
As far as I understand, you have to try out this column width,
until the list looks good - is that right?

Mike:
I looked for PADR in the help at VFP - but at first I couldn't find anything - until I tried PADL - only then you can see the explanation for the PAD function there.
That's good to know. Now I understand the function.
Thanks.

Peace worldwide - it starts here...
 
Hi,

As far as I understand, you have to try out this column width, until the list looks good - is that right?

Yes, since I don't know the width of the underlying fields

hth

MarK
 
you have to try out this column width,until the list looks good - is that right?

Yes, that's right. It's a matter of trial and error. At least, that's how I do it.

Re PADR(), I can see it in the Help index. It leads to the same Help topic for all three PADx() functions, but it is definitely in the index in its own right. But not to worry. You found it in the end.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
The best way to get ColumnWidths right is to set it to something you think is close and then run the form in the VFP IDE. Open the Debugger and put _SCREEN.ActiveForm.lstName.ColumnWidths in the Watch window (substituting the actual name of your list where I wrote lstName). Then you can try different values for ColumnWidths until you find one that looks good.

Tamar
 
Many thanks, Tamar.
That’s a good help.

Greetings from Germany
Klaus


Peace worldwide - it starts here...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top