Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TStringGrid, clicked header and cell?

2,024 views
Skip to first unread message

jodleren

unread,
Jul 21, 2010, 7:23:14 AM7/21/10
to
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

unread,
Jul 21, 2010, 11:13:07 AM7/21/10
to

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

alang...@aol.com

unread,
Jul 21, 2010, 2:42:13 PM7/21/10
to

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

unread,
Jul 22, 2010, 2:15:00 AM7/22/10
to

Thanks, it helped

jodleren

unread,
Jul 23, 2010, 11:53:59 AM7/23/10
to
On Jul 21, 9:42 pm, "alangll...@aol.com" <alangll...@aol.com> wrote:
> On 21 July, 16:13, jodleren <sonn...@hot.ee> wrote:
>
>
>
> > On Jul 21, 2:23 pm, jodleren <sonn...@hot.ee> wrote:
>
> > > 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
>
> > Most of is here:

>
> procedure TMyForm.StringGrid1MouseDown(Sender: TObject; Button:
> 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

0 new messages