在所有工作中需要显示taskid 为1 和0 的记录 但是我们领导要求分别用不同颜色区别,这个俺不会阿。高手来帮忙啊!!谢谢了!!procedure TForm4.Button1Click(Sender: TObject);
begin
  if ComboBox2.Text = '计划内工作' then
   begin
   Query1.Close;
   Query1.SQL.Clear;
   //showmessage('select * from ZHAOWEI.BZGZ where  workdate = ''' + DateToStr(Self.DateTimePicker1.Date) + '''and banzu= ''' + Trim(ComboBox1.Text) + '''and taskid= ''' + '0' + ''' ');
   Query1.SQL.Add('select * from ZHAOWEI.BZGZ where  workdate = ''' + DateToStr(Self.DateTimePicker1.Date) + '''and banzu= ''' + Trim(ComboBox1.Text) + '''and taskid= ''' + '0' + ''' ');
   Query1.ExecSQL;
   Query1.Open;
  end
  else if ComboBox2.Text = '计划外工作' then
   begin
   Query1.Close;
   Query1.SQL.Clear;
   Query1.SQL.Add('select * from ZHAOWEI.BZGZ where  workdate = ''' + DateToStr(Self.DateTimePicker1.Date) + '''and banzu= ''' + Trim(ComboBox1.Text) + '''and taskid= ''' + '1' + ''' ');
   Query1.ExecSQL;
   Query1.Open;
   end
  else if ComboBox2.Text = '所有工作' then
   begin
   Query1.Close;
   Query1.SQL.Clear;
   Query1.SQL.Add('select * from ZHAOWEI.BZGZ where  workdate = ''' + DateToStr(Self.DateTimePicker1.Date) + '''and banzu= ''' + Trim(ComboBox1.Text) + ''' ');
   Query1.ExecSQL;
   Query1.Open;
   end
  else
    exit;
end;

解决方案 »

  1.   

    With (Sender as TDBGRID) do
        Begin
          oldpm:= Canvas.pen.mode;
          oldcolor:= Canvas.Brush.color;
          Canvas.Brush.color:=newColor;
          Canvas.pen.mode:=pmmask;
          DefaultDrawColumnCell(Rect,DataCol,Column,State);
          Canvas.Brush.color:=oldcolor;
          Canvas.pen.mode:=oldpm;
        End;
      

  2.   

    在DbGrid1的OnDrawColumnCell事件写
     if Query1.FieldByName('taskid').AsInteger=1 then
      DBGrid1.Canvas.Brush.Color := clBlue
     else  DBGrid1.Canvas.Brush.Color := clRed; DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
      

  3.   

    procedure TForm4.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    begin
       if  Query1.FieldByName('taskid').AsString='1'  then
       DBGrid1.Canvas.Font.Color:= clblue
       else
       DBGrid1.Canvas.Font.Color:= clwindowText;
       dbGrid1.DefaultDrawColumnCell(rect, datacol, column, state);end;end.可以了
      

  4.   

    我想问问 刚开始 我没有加dbGrid1.DefaultDrawColumnCell(rect, datacol, column, state);可以编译 可以执行 但是就是不显示颜色 这是为什么啊??