如何在DBGrid中用不同的颜色显示数据!

解决方案 »

  1.   

    procedure TForm1.DBGridEh1DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumnEh;
      State: TGridDrawState);
    begin
     if not (gdFixed in State) then
      begin
       if Column.index=1 //第一列.
        with DBGridEh1.Canvas do
        begin
        if DataModule1.Query1.fieldbyname('余额')>0 then
                 Brush.Color := clred
          else
            Brush.Color:=clblue;
          FillRect(Rect);
          Font.Color:=clblack;
          TextOut(Rect.Left, Rect.Top, Field.AsString);
        end;
      end;  
    end;end.
      

  2.   

    非常感谢!TextOut(Rect.Left, Rect.Top, Field.AsString) 这行是什么意思呀!而且不能运行,我把(Field.AsString)改成(Fields[0].AsString)指定列,但DBGrid 一直刷新不停!
      

  3.   

    with dbgrid1.datasource.dataset do
      begin
      if recno=1then
      begin
         dbgrid1.Canvas.Brush.Color:=clbtnface;
       end;       
        dbgrid1.DefaultDrawColumnCell(Rect, DataCol, Column,[gdFixed,gdFocused,gdSelected]);
      

  4.   

    http://expert.csdn.net/Expert/topic/1511/1511481.xml?temp=.5748712进去看看。都通过测试了的。