Kbase 13860: Associating a COMBO-BOX with a database field: HOW TO
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  5/10/1998 |
|
Associating a COMBO-BOX with a database field: HOW TO
When associating a combo-box widget with a database field, the
combo-box does not know to go into the database and automatically
extract the possible values for the field that should be loaded
into its drop-down list.
For example, you might have three different sales-rep records stored
in your salesrep table, where salesrep.sales-rep would be equal to
ABC, DEF, and GHI, respectively. If you have another field in
another table that utilizes the sales-rep field, and if you wanted
to associate it with a combo-box, you'd want to load the drop-down
list of the combo-box to include each of these three sales-reps.
Let's say you wish to use a combo-box for Customer.Sales-rep in the
sports database. Note that the steps are somewhat different
in version 7 and in version 8 using Smart Objects. The version
8 steps are in a subsequent section of this knowledgebase
entry.
In the version 7 UIB, the steps to do this would be:
(1) Create a combo-box widget.
(2) Go into the combo-box Property Sheet and select the "Fields"
button. Choose the Customer.Sales-rep field.
(3) Go into the Section Editor and select the "Definitions" area.
Once there, define a logical variable:
DEF VAR stat AS LOGICAL NO-UNDO.
(4) Now select the "Main Block" and add the following loop just
before the RUN ENABLE_UI statement:
FOR EACH salesrep:
stat = Customer.Sales-rep:ADD-LAST(salesrep.sales-rep)
IN FRAME frame-a.
END.
It's crucial to note that although it is a Customer table
field that's being represented as the combo-box, we area
using the actual Salesrep table to initialize the field with
the possible values. This is one reason that PROGRESS does
not know how to initialize the values automatically: there is
no way for the UIB to know that the Customer.Sales-rep should
be initialized using the records in a separate table.
Solving this problem with Smart Objects:
=======================================
The steps for solving this problem with version 8 Smart Objects are
as follows:
(1) Place a combo-box widget in a Smart Object, for example a
Smart Viewer.
(2) Go into the Section Editor and select the "Definitions"
area. Once there, define a logical variable:
DEFINE VARIABLE stat AS LOGICAL NO-UNDO.
(3) In the Section Editor, click on New... to make a new
Procedure. Select Local ADM Event. Click on the down arrow
on the Source field. Find adm-update-record and
adm-initialize, to create local versions as shown below.
/*--------------------------------------------------------------------
Purpose: Override standard ADM method
Notes: local-update-record
---------------------------------------------------------------*/
/* Code placed here will execute PRIOR to standard behavior. */
/* Dispatch standard ADM method. */
RUN dispatch IN THIS-PROCEDURE ( INPUT 'update-record':U ) .
/* Code placed here will execute AFTER standard behavior. */
customer.sales-rep = combo-box-1:screen-value in frame {&frame-name}.
END PROCEDURE.
/*-------------------------------------------------------------*/
Purpose: Override standard ADM method
Notes: local-initialize
---------------------------------------------------------------*/
/* Code placed here will execute PRIOR to standard behavior. */
FOR EACH salesrep:
stat = combo-box-1:ADD-LAST(salesrep.sales-rep)
IN FRAME {&frame-name}.
END.
/* Dispatch standard ADM method. */
RUN dispatch IN THIS-PROCEDURE ( INPUT 'initialize':U ) .
/* Code placed here will execute AFTER standard behavior. */
END PROCEDURE.
Progress Software Technical Support Note # 13860