Kbase P12674: How to reselect selected rows in a SmartDataBrowser after rows have been logically reordered and the
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  02/12/2008 |
|
Status: Verified
GOAL:
How to reselect selected rows in a SmartDataBrowser after rows have been logically reordered and the underlying SmartDataObject has been reopened?
FACT(s) (Environment):
Progress 9.1D
Progress 9.1E
OpenEdge 10.x
Windows
FIX:
The following sample code (which runs against the sports2000 database) will show how to reselect the selected rows in a multi-select SmartDataBrowser after the underlying SmartDataObject has had its query reopened. The SmartDataObject is based upon a temp-table.
1) Start the AppBuilder and connect to the sports2000 database.
2) Create a SmartDataObject. Base it on a temp-table using XCustomer as the name of the temp-table and use the Customer table as the base table.
3) Create an initializeObject internal procedure and place the following code into it:
FOR EACH Customer NO-LOCK:
CREATE XCustomer.
BUFFER-COPY Customer TO XCustomer.
END.
RUN SUPER.
/* Code placed here will execute AFTER standard behavior. */
4) Create an openQuery function and place the following code into it:
DEFINE VARIABLE lResult AS LOGICAL NO-UNDO.
ASSIGN lResult = SUPER().
IF lResult = TRUE THEN
DO:
RUN fetchLast.
RUN fetchFirst.
END.
5) Save the SmartDataObject as DXCustomer.w.
6) Create a SmartDataBrowser. Base it on the SmartDataObject named DXCustomer.w and add CustNum, Name, Phone, Credit Limit and Balance to the list of fields that will be displayed in the SmartDataBrowser.
7) Replace the existing code in the VALUE-CHANGED trigger with the following code:
{src/adm2/brschnge.i}
DEFINE VARIABLE iNumSelectedRows AS INTEGER NO-UNDO.
DEFINE VARIABLE iLoop AS INTEGER NO-UNDO.
DEFINE VARIABLE hField AS HANDLE NO-UNDO.
ASSIGN cSelectedRows = ''
iNumSelectedRows = {&BROWSE-NAME}:NUM-SELECTED-ROWS
hField = {&BROWSE-NAME}:QUERY:GET-BUFFER-HANDLE(1):BUFFER-FIELD("CustNum").
DO iLoop = 1 TO iNumSelectedRows:
{&BROWSE-NAME}:FETCH-SELECTED-ROW(iLoop).
IF cSelectedRows <> '' THEN
ASSIGN cSelectedRows = cSelectedRows + ',' + TRIM(hField:STRING-VALUE).
ELSE
ASSIGN cSelectedRows = TRIM(hField:STRING-VALUE).
END.
8) Create a reselectRows internal procedure and place the following code into it:
DEFINE VARIABLE iNumSelected AS INTEGER NO-UNDO INITIAL 0.
DEFINE VARIABLE iNumInList AS INTEGER NO-UNDO.
DEFINE VARIABLE iNumResults AS INTEGER NO-UNDO.
DEFINE VARIABLE iLoop AS INTEGER NO-UNDO.
DEFINE VARIABLE hQuery AS HANDLE NO-UNDO.
DEFINE VARIABLE hField AS HANDLE NO-UNDO.
ASSIGN iNumInList = NUM-ENTRIES(cSelectedRows).
IF iNumInList > 0 THEN
DO WITH FRAME {&FRAME-NAME}:
ASSIGN hQuery = {&BROWSE-NAME}:QUERY
hField = hQuery:GET-BUFFER-HANDLE(1):BUFFER-FIELD("CustNum")
iNumResults = hQuery:NUM-RESULTS.
DO iLoop = 1 TO iNumResults:
hQuery:REPOSITION-TO-ROW(iLoop).
IF LOOKUP(TRIM(hField:STRING-VALUE),cSelectedRows) > 0 THEN
DO:
{&BROWSE-NAME}:SELECT-FOCUSED-ROW().
ASSIGN iNumSelected = iNumSelected + 1.
IF iNumSelected = iNumInList THEN
LEAVE.
END.
END.
END.
9) Save the SmartDataBrowser as BXCustomer.w.
10) Create a SmartWindow.
11) Drop an instance of both DXCustomer.w and BXCustomer.w onto the SmartWindow.
12) Add a button to the SmartWindow and .place the following code into the buttons CHOOSE trigger:
DYNAMIC-FUNCTION('openQuery':U IN h_DXCustomer).
RUN reselectRows IN h_BXCustomer.
13) Save the SmartWindow as WXCustomer.w.
14) Run the SmartWindow.
15) Select multiple rows in the SmartDataBrowser.
16) Click the button.
.