Board index » cppbuilder » DBGrids

DBGrids


2003-07-15 07:30:55 PM
cppbuilder22
Hi there,
Is it possible to display certain rows in DBGrid in one color,
and other rows in another color? Some commercial components can
do that so surely there must be a way to do it yourself with
just the standard DBGrid?
Thanks for your help!
 
 

Re:DBGrids

"Andrew" < XXXX@XXXXX.COM >wrote:
Quote
Is it possible to display certain rows in DBGrid in one
color, and other rows in another color?
Sure. Set the grids DefaultDrawing property to false and add
an OnDrawDataCell event:
void __fastcall TForm1::DBGrid1DrawDataCell(TObject *Sender,
const TRect &Rect, TField *Field, TGridDrawState State)
{
TCanvas *pCanvas = DBGrid1->Canvas;
// do some kind of testing to determine what color to use
if( State.Contains( gdSelected ) )
{
pCanvas->Brush->Color = clBlack;
pCanvas->Font->Color = clHighlightText;
}
else if( Field->FieldName == "Some Name" )
{
}
else if( Field->AsString == "Some Possible Value" )
{
}
else
{
pCanvas->Brush->Color = (TColor) RGB( 255, 247, 224 );
pCanvas->Font->Color = clBlack;
}
DBGrid1->DefaultDrawDataCell( Rect, Field, State );
}
 

Re:DBGrids

"Andrew" < XXXX@XXXXX.COM >wrote in message
Quote
Is it possible to display certain rows in DBGrid
in one color, and other rows in another color?
You will have to owner-draw the grid for that. Look at the OnDrawColumnCell
event.
Gambit
 

{smallsort}