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!

How come its not sorting... please help... 2

Status
Not open for further replies.

Mandy_crw

Programmer
Jul 23, 2020
585
PH
i have this oblect that included "sorted = .t." but it does not sort data in my combobox... may i ask help please... thanks...

ADD OBJECT text4 AS COMBOBOX WITH ; && complete Name
Height = 23, ;
Left = 120, ;
Top = 75, ;
Height = 23, ;
RowSourceType = 6, RowSource = "Alltrim(tsulat.sname) + ', ' + ALLTRIM(tsulat.fname)",;
sorted = .t.,;
Width = 300
 
Hi

This question has come up before, and to quote Mike Lewis from 2011
You can't use the built-in sorting if your Rowsourcetype is 6 (Fields). The only way to do it would be to index the table based on the required order before you populate the combo.

Alternatively, do as Griff suggested: create a cursor in the desired order. But you would still use Rowsourcetype = 6 (Fields); just base the Rowsource on the cursor rather than the table.

Another option would be to loop through the table, adding each row in turn via AddItem(), and then set the combo's Sorted property to .T. But that would be more work than the other methods.

Mike

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Griff, well done in finding that post, which I see is from ten years ago. I have no recollection of posting it.

Mandy, I would go with the first of my above suggestions:

index the table based on the required order before you populate the combo

In fact, you don't need to actually index the table each time you populate the combo. Just create the index once. It will be automatically updated as you add, update and delete records. Then just SET ORDER to it before you populate the combo.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
hi griff and mike.... I've used the cursor and it worked!!!! thank you so much...

SELECT ALLTRIM(sname) + ", "+ ALLTRIM(fname), idnum FROM sms ORDER by sname INTO CURSOR MyCust

my only problem is, it does not return a correct idnum corresponding to selected name in the combobox... may i ask help please... thanks.....
 
Mandy, when you use RowSourceType = 6, the cursor stays in sync. with the combobox. In other words, when the user moves the highlight to a particular row in the combo, VFP will move the record pointer to the corresponding record in the cursor. So to find the ID corresponding to a particular name, just look in the Idnum field in the cursor.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
You might do better to order by sname and fname

Code:
SELECT ALLTRIM(sname) + ", "+ ALLTRIM(fname), idnum FROM sms ORDER by sname,fname INTO CURSOR MyCust

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Thank you so much Mike and Griff for your big help....God Bless...
 
These explanations were very valuable to me too.
Thank you for your patience with us, Griff & Mike!

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

Part and Inventory Search

Sponsor

Back
Top