Emulating a fixed row (or column) with no regular rows (or columns) 

By design, the StringGrid component will only allow the number of fixed rows or columns to be equal to or less than the number of regular rows or columns.  There are times, however, when you want only a column or row that is fixed, with no regular cells.  In such case, consider using another control such as the THeader control.  You can, however,  emulate a fixed row (or column) by using the technique below.  The example below emulates one fixed row with no other cells.

KEYWORDS: OwnerDrawn, Frame3D, TextRect
 


Be sure to set the DefaultDrawing property to false to avoid drawing everything twice which can cause flicker. 
 

//-----------------------------------------------------------------------------

//in source...
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
    StringGrid1->RowCount = 1;
    StringGrid1->FixedRows = 0;
    StringGrid1->DefaultDrawing = false;
}

//-----------------------------------------------------------------------------

void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, long Col, long Row,
TRect &Rect, TGridDrawState State)
{
     StringGrid1->Canvas->Brush->Color = clBtnFace;
     StringGrid1->Canvas->FillRect(Rect);
     Frame3D(StringGrid1->Canvas, Rect, clBtnHighlight, clBtnShadow, 1);
     StringGrid1->Canvas->TextRect(Rect, Rect.Left, Rect.Top,
                                   StringGrid1->Cells[Col][Row]);
}