首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

要db控件中字段为ABC的那一行显示为其他颜色?解决方法

2012-02-17 
要db控件中字段为ABC的那一行显示为其他颜色?void__fastcallTMainForm::DBGrid1DrawColumnCell(TObject*Se

要db控件中字段为ABC的那一行显示为其他颜色?
void   __fastcall   TMainForm::DBGrid1DrawColumnCell(TObject   *Sender,
            const   TRect   &Rect,   int   DataCol,   TColumn   *Column,
            TGridDrawState   State)
{
                                if   (Column-> FieldName==   "ABC "   )   {
                                DBGrid1-> Canvas-> Font-> Color=clRed;
                }

}

怎么不行哦???

[解决办法]
应该这样啦

void __fastcall TForm1::DBGrid1DrawDataCell(TObject *Sender,
const TRect &Rect, TField *Field, TGridDrawState State)
{
if(CompareStr(Field-> FieldName, "Gm ")==0 )
{
DBGrid1-> Canvas-> Brush-> Color=clSkyBlue;
DBGrid1-> Canvas-> Font-> Color=clRed;
DBGrid1-> Canvas-> FillRect(Rect);
DrawText(DBGrid1-> Canvas-> Handle, Field-> Text.c_str(),-1,(RECT*)&Rect,DT_SINGLELINE | DT_VCENTER |DT_CENTER);
}
}
[解决办法]
void __fastcall TMainForm::DBGrid1DrawDataCell(TObject *Sender,
const TRect &Rect, TField *Field, TGridDrawState State)
{
TDateTime dt = StrToDateTime( "2006-07-10 ");
TDBGrid *dbgrd = (TDBGrid *)Sender;
//
if(dbgrd-> DataSource-> DataSet-> FieldByName( "time ")-> AsDateTime == dt)
{
UINT uFlag;
switch(Field-> DataType) // 根据字段类型的不同,以不同的方式绘制文字
{
case ftBoolean:
uFlag = DT_SINGLELINE | DT_VCENTER | DT_CENTER | DT_WORDBREAK;
break;
case ftBCD:
case ftCurrency:
case ftSmallint:
case ftWord:
case ftInteger:
case ftLargeint:
case ftFloat:
case ftGuid:
uFlag = DT_SINGLELINE | DT_VCENTER | DT_RIGHT | DT_WORDBREAK;
break;
default:
uFlag = DT_SINGLELINE | DT_VCENTER | DT_LEFT | DT_WORDBREAK;
break;
}
dbgrd-> Canvas-> Font-> Color = clRed;
dbgrd-> Canvas-> FillRect(Rect);

DrawText(dbgrd-> Canvas-> Handle, Field-> Text.c_str(), -1,
(RECT *)&(TRect(Rect.left+2, Rect.top, Rect.right-2, Rect.bottom)),
uFlag);
}
}

热点排行