Board index » delphi » Drag&Drop in TDBGrid

Drag&Drop in TDBGrid

Delphi 5: the TDBGrid.OnDragDrop event provides the mouse
coordinates but how can I position the current row of the
associated TQuery to the row where the mouse points to?
For saving the dragged data, I need to be able to find
the primary key value at the place the user dropped.

TIA
--Joe

 

Re:Drag&Drop in TDBGrid


Hallo Joe,
Try so (not tested):

type
  THackGrid = class (TCustomDBGrid)
  public
    property DataLink;
  end;

procedure TForm1.DBGrid1DragDrop(Sender, Source: TObject; X, Y:
Integer);
var
  Coord: TGridCoord;
  OldActive: Integer;
begin
  with Sender as THackGrid do begin
    Coord := MouseCoord(X, Y);
    OldActive := DataLink.ActiveRecord;
      try
          DataLink.ActiveRecord := Coord.Y;
          MYVALUE := Fields[].Value;  // do your stuff here
      finally
          DataLink.ActiveRecord := OldActive;
      end;
   end;
end;

--
Kind regards,
Andrei Fomine, Altive Software Ltd., i...@dbaltgrid.com
DbAltGrid allows a free-form layout and hierarchical columns structure
in a DBGrid descendant. http://www.dbaltgrid.com

Quote
Joe Meyer <joe@kill_spam.iceteagroup.com> wrote in message

news:87ri4s$a2j1@bornews.borland.com...
Quote
> Delphi 5: the TDBGrid.OnDragDrop event provides the mouse
> coordinates but how can I position the current row of the
> associated TQuery to the row where the mouse points to?
> For saving the dragged data, I need to be able to find
> the primary key value at the place the user dropped.

> TIA
> --Joe

Re:Drag&Drop in TDBGrid


just to let you know: the solution works if your replace
"DataLink.ActiveRecord := Coord.Y;"
by
"DataLink.ActiveRecord := Coord.Y - 1;"

Thx,
Joe

Other Threads