Главная страница | назад





Article #16204: TDBGrid grid cell colors

 Question and Answer Database
FAQ1204C.txt TDBGrid grid cell colors
Category :Data Components
Platform :All
Product :C++Builder 1.x
Question:
How do I change the color of a grid cell in a TDBGrid?
Answer:
Enter the following code in the TDBGrid's OnDrawDataCell event:
void __fastcall TForm1::DBGrid1DrawDataCell(TObject *Sender, constTRect &Rect,
TField *Field, TGridDrawState State)
{
if (State.Contains(gdFocused)
{
DBGrid1->Canvas->Brush->Color = clRed;
DBGrid1->Canvas->Fillrect(Rect);
DBGrid1->Canvas->TextOut(Rect.Left, Rect.Top, Field->AsString);
}
}
Set the Default drawing to true. With this, it only has to draw
the highlighted cell. If you set DefaultDrawing to false, you
must draw all the cells yourself with the canvas properties.
7/2/98 10:32:32 AM

Last Modified: 01-SEP-99