Skip to content

ContextMenu - cCJGridColumn

Used to provide a custom context menu for this column. Passes default context menu, returns actual menu to use.

Type: Function
Return Data Type: Handle

Parameters

Parameter Type Description
hoMenu Handle Handle to default context menu to use as determined by the Grid object

Syntax

Function ContextMenu Handle hoMenu Returns Handle

Call Example

Get ContextMenu hoMenu to HandleVariable

Description

The ContextMenu function provides a way to customize you data cell context menus. It is passed a default Context menu, as provided by the grid, and by default it returns this handle. You can augment this function to return a different context menu or none at all (return 0). This allows you to provide custom menus at a column and even at a cell level.

When the user right-clicks on a cell, the following occurs:

  1. The grid gets a handle to a data cell context menu which is stored in phoContextMenu.

  2. The appropriate row and cell are given the focus as needed. If this fails, the process ends.

  3. If cell focus is supported (pbFocusSubItems is true) and a column was selected, ContextMenu is sent to the appropriate column object, passing the default context menu. This function returns the context menu to actually use. If it is 0, the process ends.

  4. The phoContextMenuColumn is set to the column, which can be used by the context menu to determine which column was selected.

  5. A context menu is invoked using the handle returned from ContextMenu.

By default, ContextMenu looks like this and just returns the passed context menu handle:

Function ContextMenu Handle hoMenu Returns Handle
    Function_Return hoMenu
End_Function

If you wished to assign a custom context menu to a column, you would do something like this:

Function ContextMenu Handle hoMenu Returns Handle
    Function_Return oMyCustomContxtMenu
End_Function

If you wished to have no context menu for this column, you would return 0.

Function ContextMenu Handle hoMenu Returns Handle
    Function_Return 0
End_Function

When ContextMenu is called, the SelectedRow and SelectedColumn is set and you can use this information to create cell-based context menus. In this example, we apply custom menus based on the cell's value:

Function ContextMenu Handle hoMenu Returns Handle
    String sValue
    Get SelectedRowValue to sValue
    If  (sValue="") Begin
        Move oNewDataMenu to hoMenu
    End
    Else Begin
        Move oExistingDataMenu to hoMenu
    End
    Function_Return hoMenu
End_Function

Header context menus use a similar process with the HeaderContextMenu function.

Return Value

Handle to context menu to use. If 0, no menu is invoked.