Sorting combo

tej

New Member
Hi

Ok the problem i have is that we have programs which contains combo-boxes which have different data.

so other developers will add a line in their code and pass the handle of the object.

Using this handle in the procedure which i create it will then sort the combo?

any ideas how this can be achieved????

TJ
 
You need a buffer. Sort the required data into a temp table. Then simply assign your combo values. Use a FOR EACH on the temptable, then ASSIGN the combo widget entries, this way you will read the values sequentially from the table and thus when the values are assigned to the combo widget they will be in the required order.
 
cheers i did it this way if anyones interested

define input parameter hCombo as widget-handle no-undo.
define var i as int no-undo.
define buffer bttCombo for ttCombo.

define temp-table ttCombo
field cListItem as char
index cListItem is primary clistItem ascending.

run SortCombo.

procedure SortCombo:

find first ttcombo no-error.

if not error-status:error then
delete ttCombo.

do i = 1 to num-entries(hCombo:list-items):
create ttCombo.
assign ttCombo.cListItem = entry(i,hCombo:list-items).
end.

hCombo:delete(hCombo:list-items).

if hCombo:inner-lines <> 20 then
hCombo:inner-lines = 20.

for each ttcombo:
if ttCombo.cList = "All" then
hCombo:add-first(ttCombo.cListItem).
else
hCombo:add-last(ttCombo.cListItem).
end.

find first bttCombo where bttCombo.cListItem = "All" no-error.

if available bttCombo then
hCombo:screen-value = bttCombo.cListItem.
else do:
find first bttCombo where bttCombo.clistitem <> " " no-error.
hCombo:screen-value = bttCombo.cListItem.
end.
 
The previouse post is a better solution to what I am about to prepose. You could use a bubble sort. If the values in the combo-box is relitivly small you can use the code I have written in the following link. http://www.progresstalk.com/showthread.php?t=103098&highlight=Bubble I have also written a Insert Sort which is twice a fast than a buble sort. I you want the insert Sort code let me know off line. This is just an alternative to using temp-table. I am not saying it's better but an alternative.
 
Hi

Ok the problem i have is that we have programs which contains combo-boxes which have different data.

so other developers will add a line in their code and pass the handle of the object.

Using this handle in the procedure which i create it will then sort the combo?

any ideas how this can be achieved????

TJ


I'm probably missing something here, but if the SORT attribute is set to true, ADD-FIRST/LAST will add new data in sorted order.
 
Hi

Well the reason for the program is that a table name and handle needs to be added into the program.

but i am now having problems passing a table name in? how can this be done?
 
Back
Top