Skip to main content

TcxGridBeforePopupProc Type

The procedural type for grid pop-up menu display events.

Declaration

TcxGridBeforePopupProc = procedure(ASenderMenu: TComponent; AHitTest: TcxCustomGridHitTest; X: Integer; Y: Integer; var AllowPopup: Boolean) of object;

Parameters

Name Type Description
ASenderMenu TComponent

Provides access to the grid pop-up menu component that raised the event. Different pop-up menu classes correspond to different target UI elements.

Tip

Cast the ASenderMenu parameter to the corresponding menu class to access all public API members. You can call the ASenderMenu.ClassType function to identify the actual menu component class.

AHitTest TcxCustomGridHitTest

Provides access to HitTest information calculated for the current mouse pointer position. You can use X and Y parameters to identify the current mouse pointer position.

You can use the AHitTest parameter to identify the right-clicked UI element of the parent Data Grid. To access all public API members, you need to cast the AHitTest parameter value to the corresponding terminal TcxCustomGridHitTest class descendant.

Tip

The HitTest type depends on the type of the right-clicked data grid UI element. You can call the AHitTest.ClassType function to identify the actual HitTest object type.

X Integer

Returns the pixel distance between the mouse pointer and the left border of the associated data grid’s client area.

Y Integer

Returns the pixel distance between the mouse pointer and the top border of the associated data grid’s client area.

AllowPopup Boolean

Use this parameter to prevent the pop-up menu from appearing under specific conditions:

True
Default. The pop-up menu appears in response to a right-click within the data grid’s client area.
False
The pop-up menu does not appear in response to the right-click that raised the event.

Remarks

The grid pop-up menu display event occurs every time the menu is about to appear. You can handle this event to identify the right-clicked UI element and prevent the pop-up menu from appearing in certain cases.

Code Example

The code example in this section prevents the pop-up menu from appearing when a user right-clicks the Price column’s header in an unbound grid Table View.

How to Test this Code Example

Follow the steps below to test this code example in your RAD Studio IDE:

  1. Copy the DFM code snippet below.
  2. Create a new project in the IDE and focus an empty form.
  3. Press Ctrl+V to populate the form with preconfigured components.
  4. Select cxGrid1DBTableView1 in the TcxGrid on the form.
  5. Create an empty OnPopup event handler, paste the code example, and run the project.
object cxGrid1: TcxGrid
   Left = 96
   Top = 72
   Width = 250
   Height = 200
   TabOrder = 0
   object cxGrid1TableView1: TcxGridTableView
     Navigator.Buttons.CustomButtons = <>
     ScrollbarAnnotations.CustomAnnotations = <>
     DataController.Summary.DefaultGroupSummaryItems = <>
     DataController.Summary.FooterSummaryItems = <>
     DataController.Summary.SummaryGroups = <>
     DataController.Data = {
       660000000F00000044617461436F6E74726F6C6C657231020000001200000054
       6378537472696E6756616C75655479706512000000546378537472696E675661
       6C75655479706501000000445855464D540000050000004E0061006D00650031
       00000200000031003000}
     object cxGrid1TableView1Column2: TcxGridColumn
       Caption = 'Name'
     end
     object cxGrid1TableView1Column1: TcxGridColumn
       Caption = 'Price'
     end
   end
   object cxGrid1Level1: TcxGridLevel
     GridView = cxGrid1TableView1
   end
 end
 object cxGridPopupMenu1: TcxGridPopupMenu
   Grid = cxGrid1
   PopupMenus = <
     item
       GridView = cxGrid1TableView1
       HitTypes = [gvhtColumnHeader]
       Index = 0
       PopupMenu = PopupMenu1
     end>
   Left = 196
   Top = 72
 end
 object PopupMenu1: TPopupMenu
   Left = 472
   Top = 160
   object Item1: TMenuItem
     Caption = 'Item1'
   end
 end
uses
  cxGridPopupMenu;  // This unit declares the TcxGridPopupMenu class
// ...

procedure TMyForm.cxGridPopupMenu1Popup(ASenderMenu: TComponent;
  AHitTest: TcxCustomGridHitTest; X, Y: Integer; var AllowPopup: Boolean);
var
  AColumn: TcxGridColumn;
begin
  if AHitTest is TcxGridColumnHeaderHitTest then
  begin
    AColumn := (AHitTest as TcxGridCustomHeaderHitTest).Column;
    if AColumn.Caption = 'Price' then
      AllowPopup := False; // Disables the pop-up menu for the "Price" column
  end;
end;

Direct TcxGridBeforePopupProc Type Reference

The TcxGridPopupMenu.OnPopup event references the TcxGridBeforePopupProc procedural type.

See Also