让cxGrid像Excel那样高亮显示选区的行号列标

  Developer Express的cxGrid控件是一个相当有特色的数据栅格组件,支持自动分组、卡片式显示、和像Excel那样的过滤功能等。不过它在多选区时的显示方式却不太友善,对于我这样还有点追求的人来说肯定是不会满足的了,于是通过它的OnDrawColumnHeader事件和OnDrawIndicatorCell事件把它变成像Excel那样以高亮显示行号列标。一切以图片说话,如下图:
cxGrid高亮显示行号列标

PS:我平时是用来显示数据的,没有考虑编辑状态;为了说明效果,cxGrid使用DBTableView并设成允许多选和选区方式(在OptionsView里有设)。

OnDrawColumnHeader事件源码如下:
procedure TfrmAccount.cxtvMasterCustomDrawColumnHeader(
  Sender: TcxGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxGridColumnHeaderViewInfo; var ADone: Boolean);
var
    AButtonState: TcxButtonState;
    ARect: TRect;
begin
    if AViewInfo.Column.Selected then begin
        AButtonState := cxbsHot;
        ARect := AViewInfo.Bounds;
        Sender.LookAndFeelPainter.DrawHeader(ACanvas, ARect, AViewInfo.TextAreaBounds
            , [], cxBordersAll, AButtonState, AViewInfo.Column.HeaderAlignmentHorz
            , AViewInfo.Column.HeaderAlignmentVert, False, False
            , AViewInfo.Column.Caption, ACanvas.Font, Sender.Styles.Selection.TextColor
            , Sender.Styles.Selection.Color);
{========================================================================
  DESIGN BY :  彭国辉
  DATE:        2007-03-02
  SITE:       
http://kacarton.yeah.net/
  BLOG:        http://blog.csdn.net/nhconch
  EMAIL:       kacarton#sohu.com
  文章为作者原创,转载前请先与本人联系,转载请注明文章出处、保留作者信息,谢谢支持!
=========================================================================}

        ARect.Left := ARect.Right - 19;
        ARect.Right := ARect.Right - 1;
        InflateRect(ARect, -1, -3);
        if AViewInfo.Column.Options.Filtering then begin
            Sender.LookAndFeelPainter.DrawFilterDropDownButton(ACanvas, ARect
                , cxbsNormal, AViewInfo.Column.Filtered);
            OffsetRect(ARect, -16, 0);
        end;
        if AViewInfo.Column.SortIndex <> -1 then
            Sender.LookAndFeelPainter.DrawSortingMark(ACanvas, ARect
                , AViewInfo.Column.SortOrder=soAscending);
        ADone := true;
    end;
end;

OnDrawIndicatorCell事件源码如下:
procedure TfrmAccount.cxtvMasterCustomDrawIndicatorCell(
  Sender: TcxGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ADone: Boolean);
var
    AButtonState: TcxButtonState;
    clFont, clBrush: TColor;
begin
    if not (AViewInfo is TcxGridIndicatorRowItemViewInfo) then Exit;

    if TcxGridIndicatorRowItemViewInfo(AViewInfo).GridRecord.Selected then begin
        AButtonState := cxbsHot;
        if Sender.LookAndFeelPainter.LookAndFeelStyle = lfsOffice11 then begin
            clFont := ACanvas.Font.Color;
            clBrush := ACanvas.Brush.Color;
        end else begin
            clFont := Sender.Styles.Selection.TextColor;
            clBrush := Sender.Styles.Selection.Color;
        end;
    end else begin
        AButtonState := cxbsNormal;
        clFont := ACanvas.Font.Color;
        clBrush := ACanvas.Brush.Color;
    end;
    Sender.LookAndFeelPainter.DrawHeader(ACanvas, AViewInfo.ContentBounds,
        AViewInfo.ContentBounds, [], [bLeft, bRight, bBottom], AButtonState, taCenter
        , vaCenter, False, False, IntToStr(TcxGridIndicatorRowItemViewInfo(AViewInfo).GridRecord.Index + 1)
        , ACanvas.Font, clFont, clBrush);
    ADone := True;
end;

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值