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

drag & drop within dbgrid

128 views
Skip to first unread message

Joao Barbosa

unread,
Nov 21, 2002, 11:32:51 PM11/21/02
to
Is there any way to drag and drop a record within a dbgrid?. I want to be
abble to drag a record to a new location, then update a key field to make it
fit in the given location. If this is possible I would appreciate an example

Thank You
Joao


Robert Kaplan

unread,
Nov 22, 2002, 9:59:57 AM11/22/02
to
"Joao Barbosa" <job...@yebo.co.za> wrote in message
news:3dddb36f$1...@newsgroups.borland.com...

> Is there any way to drag and drop a record within a dbgrid?. I want to be

On start drag, save the key of the dragged item in some global. Then,
something like (untested)

Procedure tForm1.DBGridDragDrop(Sender, Source : TObject; X, Y : Integer);
var gc : TGridCoord;
NewKey : Integer;
begin
gc := DBGrid.MouseCoord(x, y);
If (gc.y > 0) and (gc.x > 0) then
begin
DataSet.MoveBy(gc.y - DBGrid.Row);
// you are now positioned in the dataset where you want to insert the new
record. Figure out the new key
Dataset.DisableControls;
DataSet.Locate('Key', Dragged, []);
DataSet.Edit;
DataSet.FieldByName('key').AsInteger := NewKey;
DataSet.Post;
DataSet.Enablecontrols;
end;
DBGrid.SetFocus;
end;

Robert


0 new messages