1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
procedure TForm1.FormCreate(Sender: TObject);
begin
StringGrid1.Cols[0].Add('Premier');
StringGrid1.Cols[1].Add('Deuxième');
StringGrid1.Cols[2].Add('Troisième');
StringGrid1.Cols[3].Add('Quatrième');
StringGrid1.Cols[4].Add('Cinquième');
//Construction des menus déroulant.
StringGrid1.Objects[0,0] := newPopupMenu(Self,'First',paLeft,True,[NewItem('Premier',TextToShortCut(''),False,True,nil,0,'Item1')]);
StringGrid1.Objects[1,0] := newPopupMenu(Self,'Two',paLeft,True,[NewItem('Deuxième',TextToShortCut(''),False,True,nil,0,'Item1')]);
StringGrid1.Objects[3,0] := newPopupMenu(Self,'three',paLeft,True,[NewItem('Quatrième',TextToShortCut(''),False,True,nil,0,'Item1')]);
end;
procedure TForm1.StringGrid1ContextPopup(Sender: TObject; MousePos: TPoint;
var Handled: Boolean);
Var
CurrCol,CurrRow: Integer;
begin
If Not (Sender is TStringGrid) Then
Exit;
With Sender as TStringGrid Do
Begin
MouseToCell(MousePos.X,MousePos.Y,CurrCol,CurrRow);
Case CurrCol Of
0:
PopupMenu := (Objects[CurrCol,0] as TPopupMenu);
1:
PopupMenu := (Objects[CurrCol,0] as TPopupMenu);
3:
PopupMenu := (Objects[CurrCol,0] as TPopupMenu);
Else
PopupMenu := nil;
End;
End;
end; |
Partager