[Lazarus] Problems drag&dropping from a TStringGrid
Luca Olivetti
luca at wetron.es
Tue Jul 8 13:20:00 CEST 2008
En/na Luca Olivetti ha escrit:
> I'm porting some delphi code. In one of my forms I drag from a
> TStringGrid and drop to a TSpinEdit (to "visually" put the value in one
> of the rows of the string-grid in one of multiple spin edits).
> The first problem is that TSpinEdit doesn't expose OnDragDrop and
> OnDragOver (I just made a derived component to publish those
> properties), but the real problem is that while I drag the selected row
> in the stringgrid changes. Is there any way to avoid that?
I finally did it this way: move the BeginDrag in MouseMove instead of
MouseDowm, track the button in MouseDown, disallow cell selection while
dragging in SelectCell.
procedure TAjustesSortens.TelegramaFisExit(Sender: TObject);
begin
FSelectedRow:=0;
end;
procedure TAjustesSortens.TelegramaFisMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
FSelectedRow:=0;
if Button=mbLeft then FClicked:=true;
end;
procedure TAjustesSortens.TelegramaFisMouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer);
begin
if FClicked then
begin
with Sender as TStringGrid do
begin
if (Row>0) then
begin
FSelectedRow:=Row;
BeginDrag(false);
end;
end
end;
end;
procedure TAjustesSortens.TelegramaFisMouseUp(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
FClicked:=false;
end;
procedure TAjustesSortens.TelegramaFisSelectCell(Sender: TObject; aCol,
aRow: Integer; var CanSelect: Boolean);
begin
if FSelectedRow>0 then CanSelect:=false;
end;
>
> This is what I have in my code:
>
> //The Mouse Down event handler of the TStringGrid
> procedure TAjustesSortens.TelegramaFisMouseDown(Sender: TObject;
> Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
> begin
> if Button=mbLeft then
> begin
> with Sender as TStringGrid do
> begin
> if (Row>0) then BeginDrag(false);
> end
> end;
>
> end;
>
> //Drag over event handler shared by all SpinEdits
> procedure TAjustesSortens.sortenDragOver(Sender, Source: TObject; X,
> Y: Integer; State: TDragState; var Accept: Boolean);
> begin
> Accept:=(Source=TelegramaFis);
> end;
>
> //Drag drop handler shared by all spinedits
> procedure TAjustesSortens.sortenDragDrop(Sender, Source: TObject; X,
> Y: Integer);
> begin
> With TelegramaFis do
> TMySpinEdit(Sender).Value:=StrToInt(Cells[0,row]);
> end;
Bye
--
Luca Olivetti
Wetron Automatización S.A. http://www.wetron.es/
Tel. +34 93 5883004 Fax +34 93 5883007
More information about the Lazarus
mailing list