1 2 //This code will change the color of a selected cell to green 3 //--------------------------------------------------------------------------- 4 5 6 #include <vcl.h> 7 #pragma hdrstop 8 9 #include "Unit1.h" 10 //--------------------------------------------------------------------------- 11 #pragma package(smart_init) 12 #pragma resource "*.dfm" 13 TForm1 *Form1; 14 //--------------------------------------------------------------------------- 15 __fastcall TForm1::TForm1(TComponent* Owner) 16 : TForm(Owner) 17 { 18 } 19 //--------------------------------------------------------------------------- 20 21 void __fastcall TForm1::DBGrid1DrawDataCell(TObject *Sender, 22 const TRect &Rect, TField *Field, TGridDrawState State) 23 { 24 25 26 if( State.Contains(gdSelected)){ 27 DBGrid1->Canvas->Brush->Color = clGreen; 28 } 29 DBGrid1->DefaultDrawDataCell(Rect, Field, State); 30 31 32 } 33 //---------------------------------------------------------------------------