I had hardly written my reply (dated feb 8th) and I had the idea of seeing what events you provided for. Consequently I used the OnColRowMoved event to write the following code:
// Column moving procedure
procedure TForm1.tblPropertiesColRowMoved(Sender: TObject; IsColumn: Boolean;
sIndex, tIndex: Integer);
var
Row : Integer; // Count for row number busy being copied/pasted
Col : Integer; // Count for columns being swapped (Note columns are swapped progressively until the source column has been correctly inserted into its target position, and all columns between source and target are shifted accordingly)
RowCount : longint; //
TempColumn : array of variant; // Dynamic array to hold source column
ET: TEpikTimer; //// DELETE THIS PROCEDURAL TIMER FROM THE FINAL CODE
Duration : extended;
begin
ET := TEpikTimer.Create(Application); // Create timer to assess how long a routine takes
ET.Clear; // optional... timer is cleared at creation
ET.Start; // Start timer
tblProperties.BeginUpdate; // Disable table control update until after the whole table has been corrected
RowCount := tblProperties.RowCount-1; // Grab local copy of the number of rows in table
label1.caption := inttostr(RowCount);
if (RowCount > 10000) then RowCount := 10000;
setlength(TempColumn,RowCount); // Assuming the table rowcount is a believable number, dimension array to suit the column about to be moved
// If the source index is to the left of the target, then cyclically process column by column from left to right
if (sIndex < tIndex) then
begin
for Row := 0 to RowCount do TempColumn[Row] := tblProperties.cells[sIndex,Row]; // Create a copy of source column to be moved
for Col := sIndex to tIndex-1 do
for Row := 0 to RowCount do tblProperties.Cells[Col,Row] := tblProperties.Cells[Col+1,Row]; // Shift data from left column to right column for all columns between source and target columns
for Row := 0 to RowCount do tblProperties.cells[tIndex,Row] := TempColumn[Row]; // Copy moved column into its final target position
end;
// If the source index is to the right of the target, then cyclically process column by column from right to left
if (sIndex > tIndex) then
begin
for Row := 0 to RowCount do TempColumn[Row] := tblProperties.cells[sIndex,Row]; // Create a copy of source column to be moved
for Col := sIndex downto tIndex+1 do
for Row := 0 to RowCount do tblProperties.Cells[Col,Row] := tblProperties.Cells[Col-1,Row]; // Shift data from left column to right column for all columns between source and target columns
for Row := 0 to RowCount do tblProperties.cells[tIndex,Row] := TempColumn[Row]; // Copy moved column into its final target position
end;
tblProperties.EndUpdate(True); // Columns have finished being moved. Reactivate updating of table control
ET.Stop; // the timer is actually paused and can be restarted later
Duration := ET.elapsed;
label2.caption := floattostr(Duration) + ' seconds';
ET.Free;
end;
This takes about 16 seconds (on a quad core I7 4.2GHz machine!) to move column A about 30 columns down (and all subsequent column moves) for 1000 rows of cells with numbers in them. Does this seem inordinately long to you? Would I be better off using the "DeleteCol" and "CopyCell" etc. you have suggested? I don't mind re-writing my code if need be, it all makes for good practice