This can be done combining two event handlers:
- The
OnPopUp
handler of your TcxGridPopupMenu
.
- An
OnClick
handler for all your popup menu items.
The idea is to use the OnPopup
to store a reference to the item (column) and record clicked, while the OnClick
would apply the value to the cell.
Code is as following:
//in private section of your form
fItem: TcxCustomGridTableItem;
fRec: TcxCustomGridRecord;
procedure TForm1.cxGridPopupMenu1Popup(ASenderMenu: TComponent;
AHitTest: TcxCustomGridHitTest; X, Y: Integer; var AllowPopup: Boolean);
begin
if AHitTest is TcxGridRecordCellHitTest then
begin
fItem := TcxGridRecordCellHitTest(AHitTest).Item;
fRec := TcxGridRecordCellHitTest(AHitTest).GridRecord;
end;
end;
procedure TForm1.MenuItem1Click(Sender: TObject);
var
s : string;
begin
s := (sender as tmenuItem).Caption;
gridView.DataController.Values[frec.Index, fitem.Index] := StripHotKey(s);
end;
As @DavidHeffernan suggested, notice the use of StripHotKey
that removes the accelerator character mark from the menu caption.