Board index » delphi » Right click in a string grid

Right click in a string grid

I'm using the TStringGrid and need to trap the right click but also know
what row/col the user clicked in.  For some reason, the string grid will do
this for the primary mouse button click, but not for the right click.  Can
anyone tell me how I can do this without going to extremes??

Thanks in advance...
Bill Bryant

 

Re:Right click in a string grid


Hi Bill,

There are two procedures in the string grid which are :-

procedure TForm1.StringGrid1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);

procedure TForm1.StringGrid1SelectCell(Sender: TObject; Col, Row: Longint;
  var CanSelect: Boolean);

The first contains the Button parameter i.e. which button was pressed mbleft
or mbright and
you could use the MouseToCell procedure

procedure MouseToCell(X, Y: Integer; var ACol, ARow: Longint);

which will give the cell that the right mousebutton was pressed in

if Button = mbright then
begin
  MouseToCell (X, Y, MyCol, MyRow) ;
 { other stuff }
end ;

The second routine selectcell only works for the left mouse button, but what
you could do is in the mouse down or mouse up event trap the button that was
pressed i.e. MyButton := button ;

Then in the SelectCell method respond to MyButton as you wish to

Hope this helps

Martin

Quote
Bill and Elaine wrote in message <01bcf99b$9a9da100$a7765acf@p120>...
>I'm using the TStringGrid and need to trap the right click but also know
>what row/col the user clicked in.  For some reason, the string grid will do
>this for the primary mouse button click, but not for the right click.  Can
>anyone tell me how I can do this without going to extremes??

>Thanks in advance...
>Bill Bryant

Other Threads