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