Kbase P125994: How to change the sort order of a multiple selection browse and keep the selection?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  9/24/2007 |
|
Status: Unverified
GOAL:
How to change the sort order of a multiple selection browse and keep the selection?
GOAL:
How to keep multiple record selections when re-sorting a multi select browse with its column headings.
FACT(s) (Environment):
All Supported Operating Systems
OpenEdge 10.x
Progress 9.1x
FIX:
The following code creates a multiple selection browse and allows selections to be made. The records can then be re-sorted via the browse column headings and the previous selections are retained.
DEF VAR i AS i.
DEF VAR l_sort AS C.
DEFINE VARIABLE l_ok AS LOGICAL NO-UNDO.
DEF TEMP-TABLE tttest
FIELD num AS I
FIELD Chars AS C.
DEF QUERY q_tttest FOR tttest.
DEF BROWSE b_tttest QUERY q_tttest DISP num Chars WITH 5 DOWN MULTIPLE.
FORM b_tttest WITH FRAME f_1.
BROWSE b_tttest:ALLOW-COLUMN-SEARCHING = TRUE.
DO i = 1 TO 20:
CREATE tttest.
ASSIGN
tttest.num = i
tttest.Chars = CHR(ASC("Z") - i).
END.
/* Resort the browse by column header */
ON START-SEARCH OF BROWSE b_tttest DO:
DEF VAR l_col AS WIDGET-HANDLE NO-UNDO.
DEF VAR l_sel AS C NO-UNDO.
/* build comma delimited list of selected tttest.num values */
l_sel = "".
DO i = 1 TO b_tttest:NUM-SELECTED-ROWS IN FRAME f_1:
l_ok = b_tttest:FETCH-SELECTED-ROW(i).
IF l_ok THEN l_sel = l_sel + STRING(tttest.num) + ",".
END.
/* Set new query string and re-open */
l_col = SELF:CURRENT-COLUMN.
l_sort = "BY " + l_col:NAME +(IF l_sort <> "" AND ENTRY(2,l_sort," ") = l_col:NAME THEN IF NUM-ENTRIES(l_sort," ") = 3 THEN "" ELSE " DESCENDING" ELSE "").
QUERY q_tttest:QUERY-PREPARE("FOR EACH tttest " + l_sort).
QUERY q_tttest:QUERY-OPEN().
/* Read through the query and select those records previously */
/* selected before re-ordering */
GET FIRST q_tttest NO-LOCK.
REPEAT:
DO i = 1 TO b_tttest:NUM-ITERATIONS IN FRAME f_1 WHILE AVAIL(tttest):
IF LOOKUP(STRING(tttest.num),l_sel) > 0 THEN
DO:
/* Reposition to selected record & highlight it */
REPOSITION q_tttest TO ROWID ROWID(tttest).
b_tttest:SELECT-FOCUSED-ROW().
END.
GET NEXT q_tttest NO-LOCK.
END.
IF b_tttest:NUM-ITERATIONS < b_tttest:DOWN OR NOT AVAIL(tttest) THEN LEAVE.
END.
END.
OPEN QUERY q_tttest FOR EACH tttest.
UPDATE b_tttest WITH FRAME f_1.