Copy grid to another one

Good afternoon,

i have a question about copy grid.

I have two grids, the main one and the second one; the second one has one more column minssing in the first one. sometingh like

Grid1               Grdid2

Col1                  Col1

Col2                  Col2

Col3                  Col3

                          Col4

Actually i copy the grid 1 to grid 2 using a stream (grid1.savetostream and grid2.loadfromstream) but when i load the stream with the second grid, i miss the last column (because is missed in the original); At this point i need to add a new column to the second grid.

I tried with your tips (Copy a row with cell values & properties from one grid to another grid) but seems that if the second grid does not have the same (or more) rows the copy does not finish.



This is not a problem, just to improve (if possibile) the code



Thank's for reading



Daniele

I cannot reproduce this. SaveToStream(), LoadFromStream() will copy all data from all columns to the other grid.

Test code:


procedure TForm1.FormCreate(Sender: TObject);
var
  ms: TMemoryStream;
begin
  advstringgrid2.ColCount := 6;
  advstringgrid1.RandomFill(false);

  ms := TMemoryStream.Create;

  advstringgrid1.SaveToStream(ms);
  ms.Position := 0;
  advstringgrid2.LoadFromStream(ms);
  ms.Free;
end;

and this works as expected.