表格中要求看不到任何线条,但是又不能影响对列的动态属性设置

解决方案 »

  1.   

    大概这样
    procedure TForm1.cxGrid1BandedTableView1CustomDrawColumnHeader(
      Sender: TcxGridTableView; ACanvas: TcxCanvas;
      AViewInfo: TcxGridColumnHeaderViewInfo; var ADone: Boolean);
    begin
      DrawBandHeader(Sender, ACanvas, AViewInfo, ADone);
    end;procedure TForm1.DrawBandHeader(Sender: TObject; ACanvas: TcxCanvas;
      AViewInfo: TcxCustomGridViewCellViewInfo; var ADone: Boolean);
    const
      MultiLines        : array[Boolean] of Integer = (cxSingleLine, cxWordBreak);
      ShowEndEllipsises : array[Boolean] of Integer = (0, cxShowEndEllipsis);
    var
      ATextRect, ABounds: TRect;
      AFontTextColor, ABkColor: TColor;
      ABorders          : TcxBorders;
      AText             : string;
      AFont             : TFont;
      isBand            : Boolean;
    begin  ABkColor := 0;
      ABounds := AViewInfo.Bounds;
      ABorders := [bTop, bBottom, bLeft, bRight];
      AFont := ACanvas.Font;
      ATextRect := AViewInfo.ContentBounds;
      AFontTextColor := ACanvas.Font.Color;
      InflateRect(ATextRect, -1, -1);
      isBand := False;
      if AViewInfo.ClassName = 'TcxGridBandHeaderViewInfo' then
        isBand := True;  //设置颜色及鼠标移上、按下效果
      case AViewInfo.ButtonState of
        cxbsDefault, cxbsNormal, cxbsDisabled:
          ABkColor := clwhite;
        cxbsHot:
          ABkColor := $00FAE4DC;
        cxbsPressed:
          ABkColor := $908782;
      end;  if not isBand then
      begin
        AText := TcxGridColumnHeaderViewInfo(AViewInfo).Column.Caption              //列标题
      end
      else
        AText := TcxGridBandHeaderViewInfo(AViewInfo).Band.Caption;  with ACanvas do
      begin
        //填充标题颜色
        if (ABkColor <> clNone) then
        begin
          SetBrushColor(ABkColor);
          FillRect(ABounds);
        end;
        //
        if AText <> '' then
        begin
          Brush.Style := bsClear;
          Font := AFont;
          Font.Color := AFontTextColor;
          DrawText(AText, ATextRect, cxAlignmentsHorz[taCenter] or cxAlignmentsVert[vaCenter] or MultiLines[False] or ShowEndEllipsises[False]);
          Brush.Style := bsSolid;
        end;
      end;  with ABounds do
      begin
        // 这里是加边框
        ACanvas.Brush.Color := $908782;
        if (not isBand) and (TcxGridColumnHeaderViewInfo(AViewInfo).Index = 0) then
          if bLeft in ABorders then                                                 // 左边框
            ACanvas.FillRect(Rect(Left, Top, Left, Bottom));
        if isBand then
        begin
          if bTop in ABorders then                                                  //上边框
            ACanvas.FillRect(Rect(Left, Top, Right, Top));
          if bRight in ABorders then                                                //右边框
            ACanvas.FillRect(Rect(Right, Top, Right, Bottom));
          if bBottom in ABorders then                                               //下边框
            ACanvas.FillRect(Rect(Left, Bottom, Right, Bottom));
        end;
      end;
      ADone := True;end;