×
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

Listbox - Problem (2
3

Listbox - Problem (2

Listbox - Problem (2

(OP)

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


Peace worldwide - it starts here...

RE: Listbox - Problem (2

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

RE: Listbox - Problem (2

Hi Klaus,

The secret to getting the columns to line up correctly is to use the listbox's ColumnWidths 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 "15,12".

On another point, you said that you tried this:

Select alltrim (last name) + "," + alltrim (first name) from mydatei into cursor temp

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:

SELECT PADR(ALLTRIM(lastname) + " " + ALLTRIM(firstname) , 27)... etc.

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

RE: Listbox - Problem (2

(OP)
Hi, Mark and Mike
Thank you for the two valuable solutions/hints.
The list looks a lot better now.

Quote (Mark: ColumnWidths = "120, 120, 0" && Width of Columns)

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

Quote (Mike: SELECT PADR(ALLTRIM(lastname) + " " + ALLTRIM(firstname) , 27)... etc.)

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...

RE: Listbox - Problem (2

Hi,

Quote:



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

RE: Listbox - Problem (2

Quote:

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

RE: Listbox - Problem (2

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

RE: Listbox - Problem (2

(OP)
Many thanks, Tamar.
That’s a good help.

Greetings from Germany
Klaus

Peace worldwide - it starts here...

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