Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2008-07

Problems drag&dropping from a TStringGrid

4 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Luca Olivetti

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?

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

Reply by email

Luca Olivetti
to Luca Olivetti

En/na Luca Olivetti ha escrit:

Show quoted text 7 lines
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;
Show quoted text 31 lines
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

Reply by email

Jesus Reyes
to Luca Olivetti

--- El mar 8-jul-08, Luca Olivetti escribi?:

Show quoted text 25 lines
De:: Luca Olivetti Asunto: Re: [Lazarus] Problems drag&dropping from a TStringGrid A: "General mailing list" Fecha: martes, 8 julio, 2008, 6:20 am 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.

I know you found a workaround but can you test r15727? it should help.

Luca Olivetti Wetron Automatizaci?n S.A. http://www.wetron.es/

Jesus Reyes A.

__________________________________________________ Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ?gratis! Reg?strate ya - http://correo.yahoo.com.mx/

Reply by email