Einzelnen Beitrag anzeigen

Volker Z.

Registriert seit: 4. Dez 2012
Ort: Augsburg, Bayern, Süddeutschland
419 Beiträge
 
Delphi XE4 Ultimate
 
#2

AW: runtime popupmenu on specific TDBGrid cell

  Alt 24. Sep 2013, 23:35
Hallo,

if I' ve got it right, you want to display a popup menu next to the selected cell of your grid only if some conditions are fulfilled.
Why do you wanna create the popup menu at runtime? I can' t see any need. I would suggest:
  • put a TPopup component on your form
  • create all the menu items you need
  • set the AutoPopup property of your popup menu to false
  • set the PopupMenu property of your TDBGrid component to the popup menu
  • provide a OnMouseUp event handler to your TDBGrid component with code like the following
Delphi-Quellcode:
procedure TForm1.DBGrid1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  c : TGridCoord;
  p : TPoint;
begin
  if Button = mbRight then
    begin
      c := DBGrid1.MouseCoord (X, Y);
      if (c.X = 0) or (c.Y = 0) then
        // no popup on a fixed col or row
        Exit;

      if YourConditionsAreFulfilled then
        begin
          // do some adjustment to the popup menu
          p := DBGrid1.ClientToScreen (Point (X, Y));
          PopupMenu1.Popup (p.X, p.Y)
        end
    end
end;
That should do.


Best regards
Volker Zeller
  Mit Zitat antworten Zitat