×
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 create and manage a listbox
2

How to create and manage a listbox

How to create and manage a listbox

(OP)
Remark:
The following question has already been asked in thread 184-1829008 - but I was recommended to ask this question in a separate thread - so that other members of this forum can also follow this discussion better:

I have created a *.dbf file (corplook1.dbf) which has a character-field "company".
The file is not yet indexed.
Now I created a form with a listbox control - and filled that listbox (List1) on the form with properties as follows:

RowSource:
Select distinct company from corplook1 order by company
RowSourceType:
3 - SQL Statement

That works - Listbox1 is filled with the extracted companies in alphabetical order.
Now I can click....but how can I use that clicked name of the company to proceed (eg. to find more about it in a memofield?)

Possible ?, or do I have to transfer the *.dbf into an array/cursor to identify the contents by item before?

Peace worldwide - it starts here...

RE: How to create and manage a listbox

Short answer I already gave, the Listbox shows the picked item number in its ListIndex property.

And also no matter what rowsourcetype you use, the value is in the Listbox.ListItems array at the index, so the company name picked is Listbox.ListItems[Listbox.ListIndex]

Chriss

RE: How to create and manage a listbox

One more point. When you use SQL Statement you better use a select statement ending with INTO CURSOR Companies. The name of coursor is your choice, of course, but without an INTO CURSOR clause the query will create a cursor named QUERY (or QUERY2, QUERY3, etc.) and you'll also see a browse of the result, which is unnecessary and avoided.

In consequence the rowsourcetype is the same as if you'd first do the query in code anywhere beforehand and use the RowSourceType 2 - Alias, which is recommended as the better choice, even if you create a cursor or table finally available with an alias, you always have more comfort in writing it out in code then in a property, so RowSourceType 3 - SQL Statement is always the less good choice.

And besides not getting a browse of the result, you also will find the selected item in the currently pointed at record in the alias name you give with the query, so in my example of the name Companies the selected company is Companies.company. Not specifing the name yourself is bad, because as I hinted above, the name then is not known to you. For example imagine you have two or three such listsboxes on your form, you don't only need to close three browse windows that pop up when every listbox executes the query, you also have query, query2, query3,... alias names and don't know which is used in which listbox.

Chriss

RE: How to create and manage a listbox

Klaus,

You might want to consider this alternative approach:

First, create a separate cursor from Corplook1. You might do this in the listbox's Init:

SELECT DISTINCT company FROM corplook1 ORDER BY company INTO CURSOR csrCorp

Then set the RowSourceType to 6, and the RowSource to the name of the cursor (csrCorp in this example).

Now, whenever the users clicks on a row in the listbox, the record pointer in csrCorp will automatically move to the corresponding record. So all you need to do is to look at the current record in the cursor and you will see which listbox row has been selected.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: How to create and manage a listbox

(OP)
Mike & Chriss
Thank you for your precise explanations.
I am sure that I can and will use it next time.

Klaus


Peace worldwide - it starts here...

RE: How to create and manage a listbox

Klaus,

A small correction to my above post: I said to set the RecordSource to the cursor name. In fact, you also have to specify the field name. So that would be csrCorp.Company in this case.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: How to create and manage a listbox

(OP)
Ok,Mike. Thank you

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