Discussion:
TStringGrid, clicked header and cell?
(too old to reply)
jodleren
2010-07-21 11:23:14 UTC
Permalink
Hi all

In a TStringGrid, how do I:

1) get to know when a header is clicked?
2) select a cell, before my popup menu appears?
3) get to know exactly on which cell my mouse is? Also for the popup
menu?

Maybe a ClientDataSet would be easier with a DBGrid?

WBR
Sonnich
jodleren
2010-07-21 15:13:07 UTC
Permalink
Post by jodleren
Hi all
1) get to know when a header is clicked?
2) select a cell, before my popup menu appears?
3) get to know exactly on which cell my mouse is? Also for the popup
menu?
Maybe a ClientDataSet would be easier with a DBGrid?
WBR
Sonnich
Most of is here:

procedure TForm1.StringGrid1DblClick(Sender: TObject);
var
P: TPoint;
iColumn, iRow: Longint;
begin
GetCursorPos(P);
with StringGrid1 do
begin
P := ScreenToClient(P);
MouseToCell(P.X, P.Y, iColumn, iRow);
end;
end;

but how do I get a single click from a header?

Sonnich
a***@aol.com
2010-07-21 18:42:13 UTC
Permalink
Post by jodleren
Hi all
1) get to know when a header is clicked?
2) select a cell, before my popup menu appears?
3) get to know exactly on which cell my mouse is? Also for the popup
menu?
Maybe a ClientDataSet would be easier with a DBGrid?
WBR
Sonnich
  procedure TForm1.StringGrid1DblClick(Sender: TObject);
   var
     P: TPoint;
     iColumn, iRow: Longint;
   begin
     GetCursorPos(P);
     with StringGrid1 do
     begin
       P := ScreenToClient(P);
       MouseToCell(P.X, P.Y, iColumn, iRow);
     end;
   end;
but how do I get a single click from a header?
Sonnich
Set a global var MouseCell : TPoint;

procedure TMyForm.StringGrid1MouseDown(Sender: TObject; Button:
TMouseButton;
Shift: TShiftState; X, Y:
Integer);
var
ARow, ACol : integer;
begin
with StringGrid do begin
{get mouse cell indices}
MouseToCell(X, Y, ACol, ARow);
MouseCell := Point(ACol, ARow);
end;

Then you can get the coloumn & row from MouseCell in
StringGrid1Click() and do what you want if the MouseCell.Y is 0.

The OnClick event always comes after OnMouseDown.

Alan Lloyd
jodleren
2010-07-22 06:15:00 UTC
Permalink
Post by a***@aol.com
Post by jodleren
Hi all
1) get to know when a header is clicked?
2) select a cell, before my popup menu appears?
3) get to know exactly on which cell my mouse is? Also for the popup
menu?
Maybe a ClientDataSet would be easier with a DBGrid?
WBR
Sonnich
  procedure TForm1.StringGrid1DblClick(Sender: TObject);
   var
     P: TPoint;
     iColumn, iRow: Longint;
   begin
     GetCursorPos(P);
     with StringGrid1 do
     begin
       P := ScreenToClient(P);
       MouseToCell(P.X, P.Y, iColumn, iRow);
     end;
   end;
but how do I get a single click from a header?
Sonnich
Set a global var MouseCell : TPoint;
TMouseButton;
Integer);
var
  ARow, ACol : integer;
begin
  with StringGrid do begin
    {get mouse cell indices}
    MouseToCell(X, Y, ACol, ARow);
    MouseCell := Point(ACol, ARow);
  end;
Then you can get the coloumn & row from MouseCell in
StringGrid1Click() and do what you want if the MouseCell.Y is 0.
The OnClick event always comes after OnMouseDown.
Alan Lloyd
Thanks, it helped
jodleren
2010-07-23 15:53:59 UTC
Permalink
Post by a***@aol.com
Post by jodleren
Hi all
1) get to know when a header is clicked?
2) select a cell, before my popup menu appears?
3) get to know exactly on which cell my mouse is? Also for the popup
menu?
Maybe a ClientDataSet would be easier with a DBGrid?
WBR
Sonnich
TMouseButton;
Then you can get the coloumn & row from MouseCell in
StringGrid1Click() and do what you want if the MouseCell.Y is 0.
The OnClick event always comes after OnMouseDown.
Alan Lloyd
Hi there

It should me Mouse-UP, so we copy the function from Click events - the
click is on recoqnised, when the mouse has left the component

WBR
Sonnich

Loading...