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

VFP7: Combo box sorting alphabetically

Status
Not open for further replies.

cj001

Programmer
Oct 3, 2001
145
US
How do I make my combo box sort alphabetically?

At first I had Combo1 working directly with the fields in the table the data was being pulled from. I noticed that other people had the same problem and the ended up using an SQL statement putting the data to a cursor and this allowed them to get their data alphabetically. So I tried the SQL statement, but it still isn't sorted alphabetically.

In Combo1's properties (even though it isn't grayed-out) I am unable to change the Combo1's sorting from False to True. So in the Form's ACTIVE Event the following line:

thisform.combo1.Sorted = .T.

The combo still isn't sorted alphabetically.


Any ideas?

THANKS!
CJ
 
Hi CJ,

I don't know what the 'sorted' value does on a combo - I never get it to work either!

However, to get the entries sorted - make the SQL statement do it for you:

In the combo rowsource property:
Code:
Select Name,Descrip from MyTable order by Name into cursor MyComboSource

Remember to set the rowsourcetype to be 3 - SQL Statement and to explicitly release the cursor as the form is closed.

Regards

Griff
Keep [Smile]ing
 
I do the same as Griff, get the SQL to sort the results.

For what it's worth, the help says:

The Sorted property is only available if the RowSourceType property is set to 0 (None) or 1 (Value) !!!!!!!

Stewart
 
Griff thank you for your response. I was forgetting the ORDER BY. In any case it still isn't alphabetizing.


Here is my SQL code:
SELECT ALLTRIM(blname) + ", "+ ALLTRIM(bfname) FROM bauthor ORDER by baname && INTO CURSOR cbauthors


Stewart thanks for explaining that!!!!!!!!!!!!!!!!!!!!!!

:)
 
cj001

If your list would been an Array, ASORT() would have sorted it.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Not sure, but you should probably drop the double ampersand:

Code:
SELECT ALLTRIM(blname) + ", "+ ALLTRIM(bfname) FROM bauthor ORDER by baname INTO CURSOR MyComboCursor

Is baname another field?



Regards

Griff
Keep [Smile]ing
 
Thank you Mike Gagnon for your suggestion.

It looks like my index was the problem. I created a new index and now it works.

Thank you everyone!

:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top