Consultor Eletrônico



Kbase P80659: How to disable "Add" node popup menu in a TreeView depending on the value of the record fields corre
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   16/10/2008
Status: Unverified

GOAL:

How to disable "Add" node popup menu in a TreeView depending on the value of the record fields corresponding to the selected node?

FACT(s) (Environment):

Dynamics 2.1A

FIX:

The below example verifies if the value of the database salesrep_code field is equal with "AAA" and if it is then it disables the Add Node popup menu. This logical condition is placed in the tvNodeSelected procedure (see below), and should be replaced by your own logical condition, eventually by a function call on the SDO which returns TRUE or FALSE, depending on the current record - this can make the TreeView custom super procedure reusable.
Add and edit the the TreeView custom super procedure:
1. In the definition block define the variable:

DEFINE VARIABLE glPopup AS LOGICAL NO-UNDO.

2. Add the folowing internal procedure:

PROCEDURE tvNodeSelected:
/*------------------------------------------------------------------------------
Purpose:
Parameters:
Notes:
------------------------------------------------------------------------------*/
DEFINE INPUT PARAMETER pcNodeKey AS CHARACTER NO-UNDO.

DEFINE VARIABLE hTreeBuffer AS HANDLE NO-UNDO.
DEFINE VARIABLE hData AS HANDLE NO-UNDO.
DEFINE VARIABLE cc AS CHARACTER NO-UNDO.

RUN returnTreeBuffer IN TARGET-PROCEDURE (INPUT pcNodeKey, OUTPUT
hTreeBuffer).

hData =
IF hTreeBuffer:AVAILABLE THEN
hTreeBuffer:BUFFER-FIELD("sdo_handle":U):BUFFER-VALUE
ELSE ?.

RUN SUPER(pcNodeKey).
cc = {fnarg columnValue 'salesrep_code' hData} NO-ERROR.
/*I don't want to display the popup menu for records with salesrep_code = "AAA":*/

glpopup = cc <> "AAA1".




END PROCEDURE.


3. Add the following internal procedure in the TreeView custom super procedure :

PROCEDURE BuildPopupMenu
/*------------------------------------------------------------------------------
Purpose:
Parameters:
Notes:
------------------------------------------------------------------------------*/
DEFINE INPUT PARAMETER pdNodeObj AS DECIMAL NO-UNDO.
DEFINE INPUT PARAMETER pcNodeKey AS CHARACTER NO-UNDO.
DEFINE VARIABLE hPopupMenu AS HANDLE NO-UNDO.
DEFINE VARIABLE hWindow AS HANDLE NO-UNDO.
DEFINE VARIABLE hTreeViewOCX AS HANDLE NO-UNDO.
DEFINE VARIABLE hTreeFrame AS HANDLE NO-UNDO.
DEFINE VARIABLE hChild AS HANDLE NO-UNDO.

{get ContainerHandle hWindow}.
{get TreeViewOCX hTreeViewOCX}.

/* this will create the popup menu*/
RUN SUPER (pdNodeObj, pcNodeKey).

IF glPopup THEN RETURN.
/*Now disable the popup menu*/

ASSIGN hPopupMenu = hWindow:POPUP-MENU.
IF NOT VALID-HANDLE( hPopupMenu ) THEN DO:
hTreeFrame = DYNAMIC-FUNCTION("getContainerHandle":U IN hTreeViewOCX).
IF VALID-HANDLE(hTreeFrame) THEN
hPopupMenu = hTreeFrame:POPUP-MENU.
END.
ELSE ASSIGN hPopupMenu = hWindow:POPUP-MENU.

hChild = hPopupMenu:FIRST-CHILD.
hChild:SENSITIVE = NO.


/* Assign the new popup menu to the window */
hTreeFrame = DYNAMIC-FUNCTION("getContainerHandle":U IN hTreeViewOCX).
IF VALID-HANDLE(hTreeFrame) THEN
ASSIGN hTreeFrame:POPUP-MENU = hPopupMenu.
ELSE
ASSIGN
hWindow:POPUP-MENU = hPopupMenu.



END PROCEDURE.