unit StrTestUnit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls;
type
TStringGridExt =
class(TStringGrid)
protected
procedure InsertRow(ARow: Longint);
procedure DeleteRow(ARow: Longint);
end;
type
TForm2 =
class(TForm)
StringGrid1: TStringGrid;
Button1: TButton;
Button2: TButton;
StringGrid2: TStringGrid;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
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
{...}
public
{...}
end;
var
Form2: TForm2;
implementation
{$R *.DFM}
procedure TStringGridExt.InsertRow(ARow: Longint);
var
TempRow: Integer;
begin
TempRow := Row;
// Zeile zwischenspeichern
while ARow < FixedRows
do
ARow := ARow + 1;
RowCount := RowCount + 1;
MoveRow(RowCount - 1, ARow);
Row := TempRow;
Rows[Row].Clear;
end;
procedure TStringGridExt.DeleteRow(ARow: Longint);
var
GemRow: Integer;
begin
GemRow := Row;
if RowCount > FixedRows + 1
then
inherited DeleteRow(ARow)
else
Rows[ARow].Clear;
if GemRow < RowCount
then Row := GemRow;
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
TStringGridExt(StringGrid1).InsertRow(1);
end;
procedure TForm2.Button2Click(Sender: TObject);
begin
TStringGridExt(StringGrid1).DeleteRow(1);
end;
procedure TForm2.StringGrid1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState;
var Accept: Boolean);
begin
Accept := true;
//Source is TStringGridExt;
end;
procedure TForm2.StringGrid1DragDrop(Sender, Source: TObject; X,
Y: Integer);
var
lbSource,lbSender : TStringGridExt;
begin
lbSource := Source
as TStringGridExt;
lbSender := Sender
as TStringGridExt;
lbsender.InsertRow (lbSender.Row);
lbSource.DeleteRow (lbSource.Row);
end;
procedure TForm2.StringGrid1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if button = mbLeft
then with Sender
as TStringGridExt
do begin
if ItemAtPos (Point (x,y),true) >= 0
then
BeginDrag (false);
end;
end;
end.