怎么改变dbgrid指定行和列的某个单元格的颜色

解决方案 »

  1.   

    使用DBGrid的onDrawColumnCell事件
    DBGrid1DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumn;
      State: TGridDrawState);
      

  2.   

    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源码,我从程序中拷出来,你可以修改一下。
      

  3.   

    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;
      

  4.   

    要是有这样的函数多好:
    dbgrid.cell[1,2].color=red

    dbgrid.colmuns[i].row[k].color=red
    大侠们谁能实现这样的函数,我给100分啊