Consultor Eletrônico



Kbase P160055: 4GL/ABL: How to ENABLE/DISABLE browse fields ( columns) at will during runtime?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   5/28/2010
Status: Verified

GOAL:

4GL/ABL: How to ENABLE/DISABLE a BROWSE widget fields ( columns) at will during runtime?


GOAL:

How to get a BROWSE widget and a BROWSE COLUMN handles?

GOAL:

How to set the READ-ONLY attribute of a BROWSE COLUMN at run time.

GOAL:

Sample AppBuilder session to build a sample Window application to show how to set the READ-ONLY attribute of a BROWSE COLUMN at run time.

GOAL:

Is there way to delete a column from a browse at Run-Time

FACT(s) (Environment):

Windows
Progress 9.x
OpenEdge 10.x
OpenEdge Category: Language (4GL/ABL)

FIX:


The following steps construct a sample Window to demonstrates how to ENABLE/DISABLE browse fields at will during runtime.

Please note that only the fields initially listed in the browse-enable-phrase may be manipulated in this fashion during runtime. In other words, all the fields whose READ-ONLY attribute we intend to manipulate at runtime must initially be included in the ENABLE option of the browse definition.

The following is a detailed step by step procedure that I followed to build, save and run this sample window. The window has a browse and two combo boxes. One combo box is used to select a field name, the other combo box is used to select the desired action.

The code is simple and rich. It shows, amongst other things, how to get the browse handle, get the handle of a browse column given its name and set the READ-ONLY attribute of the field handle to TRUE or FALSE at run time.

1. Start a proenv session:
Start > Programs > Progress > Proenv

2. Create a copy of the sports2000 database in the default working directory:
prodb sports2000 sports2000

3. Start an AppBuilder session connected to the sports2000 in single-user mode:
prowin32 sports2000 -1 -p _ab

4. Create a new Window
File > New > Window

5. Drop a Browse widget from the object Palette into the Window and do the following tasks:
- In the Query Builder dialog, double click the Item table from the Available Tables column.
- In the Query Builder dialog, click the Fields button.
- In the Column Editor dialog, click the Add button.
- In the Multi-Field Selector dialog, double click each of the ItemNum, ItemName, Price, Onhand and
ReOrder fields.
- In the Multi-Field Selector dialog, click the OK button.
- In the Column Editor dialog, click the Enable All button.
- In the Column Editor dialog, double click the ItemNum field to disable it and click OK to return to the
Query Builder dialog
- In the Query Builder dialog, click the OK button.
- Adjust the Window and the Browse widget sizes to taste.

6. Drop a Combo Box widget from the object Palette into the Window and do the following tasks:
- Double click on the Combo Box widget to access its Property Sheet dialog.
- In the Property Sheet dialog, type cbSelectField for the Object and Select Field for the Label.
- In the Property Sheet dialog, type the following in the List-Items box:
RONG>ItemName
Onhand
Price
ReOrder
- In the Property Sheet dialog, check the Sort box in the Other Settings section.
- In the Property Sheet dialog, click the Advanced button to access the Advanced Properties dialog.
- In the Advanced Properties dialog, type ItemName for the Initial Value and click OK.
- In the Property Sheet dialog, click the OK button to dismiss the Property Sheet dialog.

7. Drop another Combo Box widget from the Palette into the Window and do the following tasks:
- Double click on the Combo Box widget to access its Property Sheet dialog.
- In the Property Sheet dialog, type cbSelectActionfor the Object and Select Action for the Label.
- In the Property Sheet dialog, type the following in the List-Items box:
Enable Field
Disable Field
Do Nothing
- In the Property Sheet dialog, check the Sort box in the Other Settings section.
- In the Property Sheet dialog, click the Advanced button to access the Advanced Properties dialog.
- In the Advanced Properties dialog, type Do Nothing for the Initial Value and click OK.
- In the Property Sheet dialog, click the OK button to dismiss the Property Sheet dialog.

8. Create the following VALUE-CHANGED trigger of the cbSelectAction COMBO-BOX widget:
DO:
DEFINE VARIABLE hBrowse AS HANDLE NO-UNDO.
DEFINE VARIABLE hColumn AS HANDLE NO-UNDO.
DEFINE VARIABLE iCounter AS INTEGER NO-UNDO.
/* Get the handle of the Browse widget */
ASSIGN
hBrowse = BROWSE BROWSE-1:HANDLE.
/* Get the handle of the selected field column */
DO iCounter = 1 TO hBrowse:NUM-COLUMNS:
hColumn = hBrowse:GET-BROWSE-COLUMN(iCounter).
IF hColumn:NAME = cbSelectField:SCREEN-VALUE THEN LEAVE.
END.
/* Apply the selected action on the selected field */
CASE cbSelectAction:SCREEN-VALUE:
WHEN "Enable Field" THEN DO:
hColumn:READ-ONLY = FALSE.
MESSAGE "The " hColumn:NAME " was enabled as requested."
VIEW-AS ALERT-BOX INFO BUTTONS OK.
END.
WHEN "Disable Field" THEN DO:
hColumn:READ-ONLY = TRUE.
. MESSAGE "The " hColumn:NAME " was disabled as requested."
VIEW-AS ALERT-BOX INFO BUTTONS OK.
END.
OTHERWISE
MESSAGE "No action specified...No action taken."
VIEW-AS ALERT-BOX INFO BUTTONS OK.
END CASE.
END.
9. Save the window as EnableDisableBrowseFieldsSampleWindow.w.

10. Run the EnableDisableBrowseFieldsSampleWindow.w.

11. Select Disable Field from the Select Action COMBO-BOX list.

12. Observe the message " The ItemName was disabled as requested." is displayed.

13. Observe also that the ItemName field is now disabled.

14. Select Enable Field from the Select Action COMBO-BOX list.

15. Observe the message " The ItemName was enabled as requested." is displayed.

16. Observe also that the ItemName field is now enabled.

Note that there is no way to remove or delete a column but you can hide it using column-name:visible in browse browse-name = false..