void __fastcall TForm1::dbgChkListDrawDataCell(TObject *Sender, const TRect &Rect, TField *Field, TGridDrawState State) { AnsiString theState = dbgChkList->DataSource->DataSet->FieldByName("STATE")->AsString; if (theState == "0") for (int i = 0 ; i < dbgChkList->Columns->Count ; i++ ) dbgChkList->Columns->Items[i]->Color = clBlue; else if (theState == "1") for (int i = 0 ; i < dbgChkList->Columns->Count ; i++ ) dbgChkList->Columns->Items[i]->Font->Color = clPurple; else if (theState == "2") for (int i = 0 ; i < dbgChkList->Columns->Count ; i++ ) dbgChkList->Columns->Items[i]->Font->Color = clRed; else if (theState == "9") for (int i = 0 ; i < dbgChkList->Columns->Count ; i++ ) dbgChkList->Columns->Items[i]->Font->Color = clOlive; DBGrid1->Canvas->Brush->Color = clLime; dbgChkList->DefaultDrawDataCell(Rect, Field, State); }这是CB源码,我从程序中拷出来,你可以修改一下。
1;将第一列的颜色设置为红色; procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); begin if column.Index = 0 then begin with dbgrid1.Canvas do begin column.Color := clred; end; end; end;
DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
const TRect &Rect, TField *Field, TGridDrawState State)
{
AnsiString theState = dbgChkList->DataSource->DataSet->FieldByName("STATE")->AsString;
if (theState == "0")
for (int i = 0 ; i < dbgChkList->Columns->Count ; i++ )
dbgChkList->Columns->Items[i]->Color = clBlue;
else if (theState == "1")
for (int i = 0 ; i < dbgChkList->Columns->Count ; i++ )
dbgChkList->Columns->Items[i]->Font->Color = clPurple;
else if (theState == "2")
for (int i = 0 ; i < dbgChkList->Columns->Count ; i++ )
dbgChkList->Columns->Items[i]->Font->Color = clRed;
else if (theState == "9")
for (int i = 0 ; i < dbgChkList->Columns->Count ; i++ )
dbgChkList->Columns->Items[i]->Font->Color = clOlive;
DBGrid1->Canvas->Brush->Color = clLime;
dbgChkList->DefaultDrawDataCell(Rect, Field, State);
}这是CB源码,我从程序中拷出来,你可以修改一下。
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if column.Index = 0 then
begin
with dbgrid1.Canvas do
begin
column.Color := clred;
end;
end;
end;
dbgrid.cell[1,2].color=red
或
dbgrid.colmuns[i].row[k].color=red
大侠们谁能实现这样的函数,我给100分啊