请问怎么设置DBGrid 某一指定单元格的颜色,不是一行是一个单元格的颜色!!做过将某一行的颜色设置 ,可是不知道怎么按某一wh 条件设置或更改指定的一个单元格的颜色?如:下面是设置一行的颜色,请问怎么设置一个单格的颜色呢??procedure TQueryForm.Query_DBGridDrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn;
  State: TGridDrawState);
begin
  with Query_DBGrid do
  begin
    if ((state=[gdselected])  or (state=[gdselected,gdfocused])) then
    begin
      canvas.Font.Color:=clyellow;
      canvas.Brush.Color:=clnavy;
    end else
    begin
      if QueryDataSource.DataSet.RecNo mod 2<>0 then
        canvas.Brush.Color:=clwhite
      else
        canvas.Brush.Color:=clred;
    end;
    defaultdrawcolumncell(rect,datacol,column,state);
  end;
end;

解决方案 »

  1.   

    if QueryDataSource.DataSet.RecNo mod 2<>0 then //修改一下这个条件
            canvas.Brush.Color:=clwhite
          else
            canvas.Brush.Color:=clred;你的条件是啥?
      

  2.   

    if QueryDataSource.DataSet.FieldByName('状态').AsString <> '故障' then
       canvas.Brush.Color:=clwhite
    else canvas.Brush.Color:=clred;
      

  3.   

    再加条件判断
    if (Column.FieldName = '状态') and (QueryDataSource.DataSet.FieldByName('状态').AsString = '故障') then
       canvas.Brush.Color:=clred
    else canvas.Brush.Color:=clwhite;