如何通过编程了来改边wwDBGrid里的每列的颜色,每个单元格的颜色

解决方案 »

  1.   

    //改变Title的颜色
    procedure TFormMain.DBGridEh1DrawTitleCell(Sender: TObject;
      Canvas: TCanvas; Field: TField; Rect: TRect;
      var DefaultDrawing: Boolean);
    begin
      if Field.FieldName = 'a'  then begin
        (Sender as TwwDBGrid).Canvas.Brush.Color:= clYellow;
        (Sender as TwwDBGrid).Canvas.FillRect(Rect);
      end else begin
        (Sender as TwwDBGrid).Canvas.Brush.Color:= clBtnFace;
        (Sender as TwwDBGrid).Canvas.FillRect(Rect);
      end;
    end;
    //改变Column的颜色
    procedure TFrmDescription.wwDBGridDescriptionCalcCellColors(
      Sender: TObject; Field: TField; State: TGridDrawState;
      Highlight: Boolean; AFont: TFont; ABrush: TBrush);
    begin
      inherited;
      if (Field.FieldName = 'aa') and  not (gdSelected in TGridDrawState(State)) then 
        ABrush.Color:= clInfoBk;
    end;