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

DBGrid - OnMouseDown

488 views
Skip to first unread message

Rogério de FREITAS

unread,
Feb 14, 2002, 10:35:36 AM2/14/02
to
Hi all!

I use a grid in a form and i wrote some code for the event
DBGridOnMouseDown. the function of this code is: Return the row and the col
i pressed the mousebutton. When i run the program and i click on a cell of
the grid, nothing happens! Except if the cell is one of the title's cells.
Please, help me!

Thank you for your attention.


Tony

unread,
Feb 14, 2002, 12:44:08 PM2/14/02
to
On Thu, 14 Feb 2002 16:35:36 +0100, Tony wrote:
It would have worked if you put the code in OnClick and then just
looked at the selected property.

Vladimir Alexandrov

unread,
Feb 16, 2002, 8:40:59 AM2/16/02
to
That is a bug in DbGrids.pas. You have to modify it to make it work.
Locate first the file DBGrids.pas which is loacted in the Source/Vcl
directory.
Open it and change the TCustomDbGrid.MouseDown implementation with this :

procedure TCustomDBGrid.MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
var
Cell: TGridCoord;
OldCol,OldRow: Integer;
MasterCol: TColumn;
begin
if not AcquireFocus then Exit;
if (ssDouble in Shift) and (Button = mbLeft) then
begin
DblClick;
Exit;
end;

if Sizing(X, Y) then
begin
FDatalink.UpdateData;
inherited MouseDown(Button, Shift, X, Y);
Exit;
end;

Cell := MouseCoord(X, Y);
if (Cell.X < 0) and (Cell.Y < 0) then
begin
inherited MouseDown(Button, Shift, X, Y);
Exit;
end;

if (DragKind = dkDock) and (Cell.X < FIndicatorOffset) and
(Cell.Y < FTitleOffset) and (not (csDesigning in ComponentState)) then
begin
BeginDrag(false);
Exit;
end;

if PtInExpandButton(X,Y, MasterCol) then
begin
MasterCol.Expanded := not MasterCol.Expanded;
ReleaseCapture;
UpdateDesigner;
Exit;
end;

if ((csDesigning in ComponentState) or (dgColumnResize in Options)) and
(Cell.Y < FTitleOffset) then
begin
FDataLink.UpdateData;
inherited MouseDown(Button, Shift, X, Y);
Exit;
end;

if FDatalink.Active then
with Cell do
begin
BeginUpdate; { eliminates highlight flicker when selection moves }
try
FDatalink.UpdateData; // validate before moving
HideEditor;
OldCol := Col;
OldRow := Row;
if (Y >= FTitleOffset) and (Y - Row <> 0) then
FDatalink.MoveBy(Y - Row);
if X >= FIndicatorOffset then
MoveCol(X, 0);
if (Button = mbLeft) and (dgMultiSelect in Options) and
FDatalink.Active then
with FBookmarks do
begin
FSelecting := False;
if ssCtrl in Shift then
CurrentRowSelected := not CurrentRowSelected
else
begin
Clear;
CurrentRowSelected := True;
end;
end;

if (Button = mbLeft) and
(((X = OldCol) and (Y = OldRow)) or (dgAlwaysShowEditor in Options))
then
begin // Added by K.S.
ShowEditor; { put grid in edit mode }
if CanEditShow then Exit; // The condition added now by K.S.
end // Added by K.S.
else
InvalidateEditor; { draw editor, if needed }
finally
EndUpdate;
end;
end;
if Assigned(OnMouseDown) then // Added by K.S.
OnMouseDown(Self, Button, Shift, X, Y); // Added by K.S.
end;

Compile this unit and place the newly created DBGrids.dcu(which should be
again in the Source\Vcl directory) in the Delphi 6\Lib directory. Now open
your project and rebuild it and it should work if you have done all that
right.
The original code is by Krzysztof Szyszka.

Cheers
---
Vladimir Alexandrov
Sweden


Rogério de FREITAS

unread,
Feb 22, 2002, 3:46:43 AM2/22/02
to
Thank you for responding

Rogério de Freitas.

"Vladimir Alexandrov" <valexand...@hotmail.com> a écrit dans le
message news: 3c6e6796$1_1@dnews...

0 new messages