Registriert seit: 15. Jun 2010
Ort: Augsburg Bayern Süddeutschland
3.470 Beiträge
Delphi XE3 Enterprise
|
AW: runtime popupmenu on specific TDBGrid cell
25. Sep 2013, 13:55
Maybe this could give some inspiration. On Popupmenu and one OnMouseUpEvent for all Grids on all Forms.
Delphi-Quellcode:
procedure TMainForm.PopUpProcedure1Click(Sender: TObject);
begin
Showmessage(TPopupMenu(TMenuItem(Sender).Owner).PopupComponent.Name);
end;
Procedure TMainform.AddPopupItem(Popup:TPopupMenu; aCaption:String;Event:TNotifyEvent);
var
MenuItem : TMenuItem;
begin
MenuItem := TMenuItem.Create(Popup);
MenuItem.Caption := aCaption;
MenuItem.OnClick := Event;
Popup.Items.Add(MenuItem);
end;
Procedure TMainForm.PreparePopupAndPopup(Sender:TDBgrid; Field:TField;p:TPoint);
begin
if Assigned(Sender.PopupMenu) then
begin
Sender.PopupMenu.Items.Clear;
if (Sender.Name='MyGrid1') then
begin // PopUpProcedure1Click should be different for different actions needed
If Field.FieldName='ID' then AddPopupItem(Sender.PopupMenu,'ID',PopUpProcedure1Click)
else If Field.FieldName='Name' then AddPopupItem(Sender.PopupMenu,'Name',PopUpProcedure1Click)
end
else if (Sender.Name='MyGrid2') then
begin
If Field.FieldName='XX' then AddPopupItem(Sender.PopupMenu,'XX',PopUpProcedure1Click)
else If Field.FieldName='YY' then AddPopupItem(Sender.PopupMenu,'YY',PopUpProcedure1Click)
end;
Sender.PopupMenu.PopupComponent := Sender;
Sender.PopupMenu.Popup(p.X,p.y);
end;
end;
procedure TMainForm.AllGridsEveryWhereMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
c : TGridCoord;
p : TPoint;
offs:Integer;
begin
if Button = mbRight then
begin
if dgIndicator in TDBGrid(Sender).Options then
offs := -1
else
offs := 0;
c :=TDBGrid(Sender).MouseCoord (X, Y);
TDBGrid(Sender).Columns[c.X + offs].Field;
if NOT ( (c.X = 0) or (c.Y = 0)) then
PreparePopupAndPopup(TDBGrid(Sender), TDBGrid(Sender).Columns[c.X + offs].Field ,TDBGrid(Sender).ClientToScreen (Point (X, Y)));
end
end;
Thomas Wassermann H₂♂ Das Problem steckt meistens zwischen den Ohren
DRY DRY KISS
H₂♂ (wenn bei meinen Snipplets nichts anderes angegeben ist Lizenz: WTFPL)
|
|
Zitat
|