请教:
    在DBGrid中对整个Column或整条记录都可以进行绘色,但不知如何对DBGrid中的某一格进行绘色?

解决方案 »

  1.   

    procedure ReBrushDBGrid(Rect:TRect;Grid:TDBGrid;Column:TColumn;
      State:TGridDrawState;cColor:TColor);
    var
      B:TRect;
      iLeft:integer;
    begin
      if Column<>要填色的列 then Exit;
      B:=Rect;
      Grid.Canvas.Brush.Color := cColor;
      case Column.Alignment of
        taLeftJustify:
          iLeft := B.Left + 2;
        taRightJustify:
          iLeft := B.Right - Grid.Canvas.TextWidth(Column.Field.DisplayText) - 3;
      else
        iLeft := B.Left + (B.Right - B.Left) shr 1
          - (Grid.Canvas.TextWidth(Column.Field.DisplayText) shr 1);
      end;
      Grid.Canvas.TextRect(B, iLeft, B.Top + 2, Column.Field.DisplayText);
    end;
      

  2.   

    好象在DRAWCELL的过程,有点儿忘了,参照你整个记录的那个,但不得用那个过程点,用下面的一个,因为第二个DRAW可以定义从哪到哪,就是可以定义从第几格到第几格.没有在单位电脑前,我也说不上,家里的电脑没装DELPHI,SORRY!!!
      

  3.   

    楼上的不对吧,应在DBGRID的一个过程中实现,然后与数据关联,这样的话,才能根据数据进行配色.具体的我忘了,明天看看,有上网再来回复!
      

  4.   

    if (Rect.Top = TStringGrid(DBGrid1).CellRect(TStringGrid(DBGrid1).col,TStringGrid(DBGrid1).row).top) and       (not (gdFocused in State)) then    Dbgrid1.Canvas.Brush.Color := clRed;  DBGrid1.DefaultDrawDataCell(Rect, Column.Field, State);
      

  5.   

    在DRAWCELL中,实现 ylhlove(ylh) 的内容,但需要进行小的改动。我不再公司记得不是特别清楚了,但是改变Canvas.Brush.Color 后好像又发送了重画消息,容易进入死循环。另外对当前State的各类型进行判断。但是注意:应该先记录下历史的Brush.Color,在单元个绘完后,再恢复历史Brush.Color。