Skip to main content

TcxGridPopupMenu.OnPopup Event

Allows you to identify the target grid View UI element and disable the predefined pop-up menu in certain cases.

Declaration

property OnPopup: TcxGridBeforePopupProc read; write;

Remarks

You can handle the OnPopup event execute custom code when the predefined pop-up menu is about to appear.

Event Occurrence

The OnPopup event occurs every time the TcxGridPopupMenu component is about to display the data grid control’s predefined pop-up menu. The AlwaysFireOnPopup property specifies if the OnPopup event occurs before the OnPopup event of the custom pop-up menu associated with the target data grid UI element.

Event Parameters

You can use ASenderMenu and AHitTest parameters to identify the menu that raised the OnPopup event and the target UI element.

X and Y parameters return the current mouse pointer coordinates.

You can assign False to the AAllowPopup parameter within an OnPopup event handler to prevent the pop-up menu from appearing.

Refer to the TcxGridBeforePopupProc procedural type description for detailed information on parameters accessible within an OnPopup event handler.

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;
See Also