Kbase 21615: ADM2. Using a Dynamic Query & a Temp-Table to Populate a Combo-Box
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  08/08/2006 |
|
Status: Verified
GOAL:
How to use a dynamic query against a temp-table to populate a combo-box defined with List-Item-Pairs.
GOAL:
Using dynamic query with temp-table to populate a List-Item-Pairs Combo-Box.
FIX:
It requires these four steps:
1) Defining a static temp-table.
2) Populating the temp-table.
3) Creating the dynamic query against the temp-table.
4) Populating the combo-box.
The code example below assumes a window which has on it a combo-box object named MyComboBox. MyComboBox is defined as having a list of 10 label-value pairs (list-item-pairs).
If the window is a SmartWindow, then place the following code in the main block after the '{src/adm2/windowmn.i}' statement. Otherwise, for a regular window, place the same code in the main block after the 'RUN enable_UI.' statement.
/* Step One:- Define and populate the temp-table MyTempTable */
DEFINE TEMP-TABLE MyTempTable NO-UNDO
FIELD iField AS INTEGER FORMAT "9999"
FIELD cName AS CHARACTER.
DEFINE VARIABLE iCounter AS INTEGER NO-UNDO.
DO iCounter = 1000 TO 2000 BY 100:
CREATE MyTempTable.
ASSIGN iField = iCounter
cName = "Name" + STRING(iCounter).
END.
/* Step Two:- Create a dynamic query using MyTempTable */
DEFINE VARIABLE qh AS WIDGET-HANDLE.
CREATE QUERY qh.
qh:SET-BUFFERS(BUFFER MyTempTable:HANDLE).
qh:QUERY-PREPARE("FOR EACH MyTempTable").
qh:QUERY-OPEN.
ASSIGN MyComboBox:LIST-ITEM-PAIRS = "" NO-ERROR.
REPEAT:
qh:GET-NEXT().
IF qh:QUERY-OFF-END THEN
LEAVE.
MyComboBox:ADD-LAST (string(iField), cName).
END.
qh:QUERY-CLOSE().
DELETE OBJECT qh.
Finally, add a VALUE-CHANGED trigger for MyComboBox. In the trigger add the code:
MESSAGE MyComboBox:SCREEN-VALUE.
Now when you run the window and change the value of the combo box, you see the list-item-pairs value for the entry selected in the combo. For example 'Name1300'.
FIX:
References to Written Documentation:
Progress Programming Handbook
Progress Language Reference