Board index » delphi » How To Assign TStringGrid Cells

How To Assign TStringGrid Cells

Is there an easy way to assign all cells from one TStringGrid to
another?  The statement

sgBottom.Assign(sgTop);

compiles, but generates an EConvert exception when I run it.  I can do
row by row or column by column as follows:

sgBottom.ColCount := sgTop.ColCount;
sgBottom.RowCount := sgTop.ColCount;
For i := 0 To sgBottom.RowCount-1 Do
  sgBottom.Rows[i].Assign(sgTop.Rows[i]);

but the help file index under "TStringGridStrings" has a topic that
leads me to believe I should be able to do it in one statement, without
the loop.

Is the loop the only way?

Craig
schel...@my-deja.com

Sent via Deja.com http://www.deja.com/
Before you buy.

 

Re:How To Assign TStringGrid Cells


Quote
In article <7uf7h2$gq...@nnrp1.deja.com>, schel...@my-deja.com writes:
>but the help file index under "TStringGridStrings" has a topic that
>leads me to believe I should be able to do it in one statement, without
>the loop.

Which topic is that - every one I've loooked at in D3 has "rows OR columns"
either explicitly or implicitly in the text.

Alan Lloyd
alangll...@aol.com

Re:How To Assign TStringGrid Cells


In article <19991019090518.02381.00000...@ngol02.aol.com>,
  alangll...@aol.com (AlanGLLoyd) wrote:

Quote
> Which topic is that - every one I've loooked at in D3 has "rows OR
columns"
> either explicitly or implicitly in the text.

Click Help | Index and enter TStringGridStrings.  I thought that might
be the key to copying an entire grid to another string grid in one
statement.

In the end I copied the grid contents as follows:

For i := 0 To sgSource.RowCount-1 Do
  sgDest.Rows[i].Assign(sgSource.Rows[i]);

But I would still like to know what TStringGridStrings is all about
because I couldn't figure out how to use it within the context of my
string grid even though I inferred from the help file that I would be
able to.

Craig
schel...@my-deja.com

Sent via Deja.com http://www.deja.com/
Before you buy.

Other Threads