grid 行颜色交替显示 - C++ Builder / Windows SDK/API
大家好:
grid控件如何能实现行颜色交替显示呀?比如奇数行背景是白色、偶数行背景色是黄色。
[解决办法]
void __fastcall TForm1::DBGridEh1DrawDataCell(TObject *Sender,const TRect &Rect, TField *Field, Gridseh::TGridDrawState State){ if(Field->DataSet->RecNo%2 == 0 ) DBGridEh1->Canvas->Brush->Color = clCream; else DBGridEh1->Canvas->Brush->Color = clWindow; DBGridEh1->DefaultDrawDataCell(Rect, Field, State); }
[解决办法]
void __fastcall TForm1::DBGridEh1DrawDataCell(TObject *Sender,const TRect &Rect, TField *Field, Gridseh::TGridDrawState State){ //选中单元不同颜色 if(State.Contains(gdSelected) || State.Contains(gdFocused)) DBGridEh1->Canvas->Font->Color = clBlue; else DBGridEh1->Canvas->Font->Color = clBlack; DBGridEh1->DefaultDrawDataCell(Rect, Field, State); }