As I told you in the Embarcadero forums...
There is no public property/method for what you are asking for. You will just have to set/increment the RowCount
property as needed, then manually shift up the contents of the Cells
property, and then finally fill in the bottom row.
if (StringGrid1->RowCount < SomeMaxValue)
StringGrid1->RowCount = StringGrid1->RowCount + 1;
for(int row = 1; row < StringGrid1->RowCount; ++row)
{
for(int col; col < StringGrid1->ColCount; ++col)
{
StringGrid1->Cells[col][row-1] = StringGrid1->Cells[col][row];
}
}
// fill in StringGrid1->Cells[...][StringGrid1->RowCount-1] for the last row as needed...
However, TStringGrid
does have a protected DeleteRow()
method, but being protected, you need to use an accessor class to reach it, eg:
class TStringGridAccess : public TStringGrid
{
public:
void RemoveRow(int row) { TStringGrid::DeleteRow(row); }
};
if (StringGrid1->RowCount > 0)
((TStringGridAccess*)StringGrid1)->RemoveRow(0);
StringGrid1->RowCount = StringGrid1->RowCount + 1;
for(int row = 1; row < StringGrid1->RowCount; ++row)
{
for(int col; col < StringGrid1->ColCount; ++col)
{
StringGrid1->Cells[col][row-1] = StringGrid1->Cells[col][row];
}
}
// fill in StringGrid1->Cells[...][StringGrid1->RowCount-1] for the last row as needed...
That said, TStringGrid
is really not the best choice for what you are trying to do. I would strongly suggest using TListView
in vsReport
mode instead. That is what I use in my log viewer, and it works very well, especially in virtual mode (OwnerData=true
), and it just looks more natural than TStringGrid
, since TListview
is a wrapper for a native Windows control whereas TStringGrid
is not.
if (ListView1->Items->Count > 0)
ListView1->Items->Items[0]->Delete();
TListItem *Item = ListView1->Items->Add();
// fill in Item->Caption (column 0) and Item->SubItems (columns 1+) as needed...