unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids;
type
TForm1 =
class(TForm)
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
procedure StringGrid2MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure StringGrid2DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState;
var Accept: Boolean);
procedure StringGrid2DragDrop(Sender, Source: TObject; X, Y: Integer);
procedure StringGrid1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState;
var Accept: Boolean);
procedure StringGrid1DragDrop(Sender, Source: TObject; X, Y: Integer);
procedure StringGrid1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private-Deklarationen }
FSourceRow: Integer;
public
{ Public-Deklarationen }
end;
type
TStringGridHack =
class(TStringGrid)
public
procedure MoveRow(FromIndex, ToIndex: Longint);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TStringGridHack.MoveRow(FromIndex, ToIndex: Integer);
begin
inherited;
end;
procedure TForm1.StringGrid1DragDrop(Sender, Source: TObject; X, Y: Integer);
var
DestCol, DestRow: Integer;
begin
StringGrid2.MouseToCell(X, Y, DestCol, DestRow);
if (FSourceRow <> DestRow)
then
begin
TStringGridHack(Source
as TStringGrid).MoveRow(FSourceRow, DestRow);
end;
end;
procedure TForm1.StringGrid1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState;
var Accept: Boolean);
var
Col, Row: Integer;
begin
(Source
as TStringGrid).MouseToCell(X, Y, Col, Row);
Accept := (Sender = Source)
and (Row > 0);
end;
procedure TForm1.StringGrid1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
SourceCol : Integer;
begin
(Sender
as TStringGrid).MouseToCell(X, Y, SourceCol, FSourceRow);
if (FSourceRow > 0)
then(Sender
as TStringGrid).BeginDrag(False, 4);
end;
procedure TForm1.StringGrid2DragDrop(Sender, Source: TObject; X, Y: Integer);
var
DestCol, DestRow: Integer;
begin
StringGrid1.MouseToCell(X, Y, DestCol, DestRow);
if (FSourceRow <> DestRow)
then
begin
TStringGridHack(Source
as TStringgrid).MoveRow(FSourceRow, DestRow);
end;
end;
procedure TForm1.StringGrid2DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState;
var Accept: Boolean);
var
Col, Row: Integer;
begin
(Source
as TStringGrid).MouseToCell(X, Y, Col, Row);
Accept := (Sender = Source)
and (Row > 0);
end;
procedure TForm1.StringGrid2MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
SourceCol : Integer;
begin
(Sender
as TStringGrid).MouseToCell(X, Y, SourceCol, FSourceRow);
if (FSourceRow > 0)
then(Sender
as TStringGrid).BeginDrag(False, 4);
end;
end.