Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Adding cells to a TStringGrid


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 1 - Last Post: Feb 4, 2015 1:25 PM Last Post By: Brian Plotkin
Brian Plotkin

Posts: 9
Registered: 9/21/01
Adding cells to a TStringGrid  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 4, 2015 1:04 PM
This should be quite simple, but the table shows no data - except for the column headers. All the appropriate rows and columns are added as expected, but the table data is BLANK. The ShowMessage (added for test purposes) in the AddData method shows '{empty}'!

void TformILFInfo::AddData(String Header, String Value)
{
  int col = findColumn(Header);
  grid->Cells[col][grid->RowCount-1]=Value;
  ShowMessage(grid->Cells[col][grid->RowCount-1]);
}
 
// ---------------------------------------------------------------------------
int TformILFInfo::findColumn(String header)
{
  for (int col = 0; col < grid->ColumnCount; col++)
  {
	if(grid->ColumnByIndex(col)->Header==header)
	{
	  return (col);
	}
  }
  TColumn *col = new TColumn(grid);
  col->Header=header;
  col->Parent=grid;
  return (col->Index);
}
// ---------------------------------------------------------------------------
Brian Plotkin

Posts: 9
Registered: 9/21/01
Re: Adding cells to a TStringGrid  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 4, 2015 1:25 PM   in response to: Brian Plotkin in response to: Brian Plotkin
Found the answer:

It needed to be TStringColumn *col = new TStringColumn(grid).

Now it works as it should have in the first place!
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02