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





Article #19583: DBGrid Row Color

 Question and Answer Database

FAQ4583C.txt - DBGrid Row Color

Category   :VCL
Platform   :All-32Bit
Product    :All-CBuilder,   

Question:
How can I change the color of a DBGrid row?

Answer:
Here is some code that demonstrates how to change the background color of
certain rows. This code makes all rows from South America yellow. This code
works with the country database that comes with BCB.


void __fastcall TForm1::DBGrid1DrawColumnCell(TObject *Sender,
      const TRect &Rect, int DataCol, TColumn *Column,
      TGridDrawState State)
{    TDataSet *dataset = Column->Field->DataSet;

    // if the country is from south america, make it yellow
    if(dataset->FieldByName("Continent")->AsString == "South America")
    {
        DBGrid1->Canvas->Brush->Color = clYellow;
    }

    // for the selected grid cell, make the text red and bold
    if(State.Contains(Grids::gdSelected))
    {
        DBGrid1->Canvas->Font->Color = clRed;
        DBGrid1->Canvas->Font->Style = TFontStyles() << fsBold;
    }

    DBGrid1->DefaultDrawColumnCell(Rect, DataCol, Column, State);
}




5/25/99 11:48:31 AM
 

Last Modified: 01-SEP-99