tdbgrid里怎么在代码里实现把第二行左对齐呢..别的不变都是原来的右对齐
RT.///
[解决办法]
在DBGrid的OnDrawDataCell事件中添加以下代码:
void __fastcall TForm1::DBGrid1DrawDataCell(TObject *Sender,
const TRect &Rect, TField *Field, TGridDrawState State)
{
TDBGrid *dbg = (TDBGrid *)Sender;
int nFormat = DT_VCENTER; // 垂直居中
RECT rct = {Rect.Left + 1, Rect.Top + 1, Rect.Right - 2, Rect.Bottom - 1};
//
if(dbg-> DataSource-> DataSet-> RecNo == 2) // 第二行
{
dbg-> Canvas-> Font-> Name = "verdana ";
dbg-> Canvas-> Font-> Size = 8;
dbg-> Canvas-> Font-> Color = clBlue;
nFormat |= DT_LEFT; // 左对齐
}
else
{
nFormat |= DT_RIGHT; // 右对齐
}
dbg-> Canvas-> FillRect(Rect);
//
::DrawText(dbg-> Canvas-> Handle, Field-> AsString.c_str(),
Field-> AsString.Length(), &rct, nFormat);
}