I got this from internet:
implementation
{$R *.lfm}
{ TForm1 }
var
SourceCol, SourceRow: integer;
procedure TForm1.FormCreate(Sender: TObject);
begin
{ Set DragMode to Manual, to control entire drag & drop by code }
SG.DragMode := dmManual;
{ For testing purposes, fill a few cells }
SG.Cells[2, 2] := 'A';
SG.Cells[3, 2] := 'B';
SG.Cells[4, 2] := 'C';
end;
procedure TForm1.ExitMenuItemClick(Sender: TObject);
begin
application.Terminate;
end;
procedure TForm1.SGMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: integer);
begin
{ Convert mouse coordinates X, Y to
to StringGrid related col and row numbers }
SG.MouseToCell(X, Y, SourceCol, SourceRow);
{ Allow dragging only if an acceptable cell was clicked
(cell beyond the fixed column and row) }
if (SourceCol > 0) and (SourceRow > 0) then
{ Begin dragging after mouse has moved 4 pixels }
SG.BeginDrag(False, 4);
end;
procedure TForm1.SGDragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
var
CurrentCol, CurrentRow: integer;
begin
SG.MouseToCell(X, Y, CurrentCol, CurrentRow); // convert mouse coord.
{ Accept dragged stuff only if it came from StringGrid
and the mouse is now over an acceptable region }
Accept := (Sender = Source) and
(CurrentCol > 0) and (CurrentRow > 0);
end;
procedure TForm1.SGDragDrop(Sender, Source: TObject; X, Y: Integer);
var
DestCol, DestRow: Integer;
begin
SG.MouseToCell(X, Y, DestCol, DestRow); // convert mouse coord.
{ Move contents from source to destination }
SG.Cells[DestCol, DestRow] := SG.Cells[SourceCol, SourceRow];
if (SourceCol <> DestCol) or (SourceRow <> DestRow) then
SG.Cells[SourceCol, SourceRow] := '';
end;
But I lose the ability to right click the mouse to activate the PopUpMenu.
What should be edited?