QuantumGrid - Disabilitar items do menu gridpopupmenu cxgrid |
Top Previous Next |
How to disable a certain Item in the standard GridPopupMenu?
Solution
If you need to disable an item in the GridPopupMenu, you should use the following approach:
1) Handle the GridPopupMenu's OnPopup event handler and assign the OnPopup event of the cxGridStdHeaderMenu(TcxGridStdFooterMenu) component which is actually popped up; 2) Navigate through all the Items of the cxGridStdPopupMenu within its OnPopup event handler, determine the required item and set its Enabled property's value to False. Here is some sample code showing how to disable the "GroupByBox" item:
[Delphi]
uses cxGridStdPopupMenu;
procedure TForm1.cxGridPopupMenu1Popup(ASenderMenu: TComponent; AHitTest: TcxCustomGridHitTest; X, Y: Integer; var AllowPopup: Boolean); begin if ASenderMenu is TcxGridStdHeaderMenu then TcxGridStdHeaderMenu(ASenderMenu).OnPopup := StdHeaderMenuPopup; end;
procedure TForm1.StdHeaderMenuPopup(Sender: TObject); var I: Integer; begin with TcxGridStdHeaderMenu(Sender).Items do for I := 0 to Count - 1 do if Items[I].Caption = 'Group By Box' then begin Items[I].Enabled := False; System.Break; end end;
|