想要在DBGrid中令显示的记录如斑马条那样:
begin
  case DataCol mod 2 = 0 of
    true: DBGrid1.Canvas.Brush.Color:=clWhite;
    false:DBGRid1.Canvas.Brush.Color:=$00DDE8FF;
  end;
  if ((State =[gdSelected]) or (State = [gdSelected,gdFocused])) then
    if not DBGrid1.SelectedRows.CurrentRowSelected then
       DBGrid1.Canvas.Brush.Color:=clRed;
  DBGrid1.Canvas.Pen.Mode:=pmMask;
  DBGrid1.DefaultDrawColumnCell(Rect,datacol,column,state);//这里总是提示出错.
end;
 检查了很久,都解决不了,请问什么问题?是不是要设置DBGrid的某些属性,或者是要声明什么?

解决方案 »

  1.   

    if DBGridEh1.DataSource.DataSet.RecNo mod 2 = 1 then//奇偶行
      begin
        DBGridEh1.Canvas.Brush.Color := $00FF0000;
      end
      else
      begin
        DBGridEh1.Canvas.Brush.Color := $00FFFFC2;
        DBGridEh1.Canvas.font.Color := $00FF0002;
      end;
      DBGridEh1.DefaultDrawColumnCell(Rect,DataCol,Column,State);if ((State = [gdSelected]) or (State=[gdSelected,gdFocused])) then//选取行
        begin
          DBGridEh1.Canvas.Font.Color :=clRed;
          DBGridEh1.Canvas.Brush.Color :=clYellow;  
          DBGridEh1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
        end;
      

  2.   

    将上面的DBGridEh1改成你的DBGrid1设DBGrid1的Options的dgRowSelect为True;
      

  3.   

    对DBGrid1的Options的dgRowSelect要设为True
    支持insert2003(高级打字员)的作法
      

  4.   

    还有你的代码没错
    procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumn;
      State: TGridDrawState);
    begin
      case DataCol mod 2 = 0 of
        true: DBGrid1.Canvas.Brush.Color:=clWhite;
        false:DBGrid1.Canvas.Brush.Color:=$00DDE8FF;
      end;
      if ((State =[gdSelected]) or (State = [gdSelected,gdFocused])) then
        if not DBGrid1.SelectedRows.CurrentRowSelected then
           DBGrid1.Canvas.Brush.Color:=clRed;
      DBGrid1.Canvas.Pen.Mode:=pmMask;
      DBGrid1.DefaultDrawColumnCell(Rect,datacol,column,state);
    end;在我机子上面运行正常
      

  5.   

    编译器老是提示DBGrid1.DefaultDrawColumnCell(Rect,datacol,column,state).出错.
    不兼容的类型:incompatible types.不知道到底什么问题?
      

  6.   

    问题解决了.
    因为在窗体中我使用了topGrid的第三方控件,产生冲突问题.把topGrid控件和声明删除后,使用DBGrid就正常了.