unit UnitDevExpressVCLCustom;
interface
uses
cxGrid, cxGridTableView, cxGridDBBandedTableView, Winapi.Windows, System.SysUtils, System.Variants, cxClasses,
System.Classes, Vcl.Graphics, cxGraphics, cxLookAndFeels, cxLookAndFeelPainters, cxCustomData, cxTextEdit, cxEdit,
cxCheckBox, Vcl.Controls, Vcl.Dialogs, cxGridDBTableView, cxGridCustomTableView, cxGridCustomView;
type
TMyCxGrid = class(TCxGrid)
private
{ Private declarations }
//变量
cxGridDBTableView: TcxGridDBTableView;
//储存过程和函数
procedure CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
AViewInfo: TcxGridTableDataCellViewInfo;
var ADone: Boolean);
public
{ Public declarations }
end;
procedure IniMyCxGrid(cxGridDBBandedTableView: TcxGridDBBandedTableView; cxGridDBTableView: TcxGridDBTableView);
implementation
procedure TMyCxGrid.CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
AViewInfo: TcxGridTableDataCellViewInfo;
var ADone: Boolean);
var
I: Integer;
lMaxRow: Integer;
Rect1: TRect;
ABorder: TcxBorder;
begin
ACanvas.FillRect(AViewInfo.Bounds);
ACanvas.DrawText(AViewInfo.GridRecord.DisplayTexts[AViewInfo.Item.Index], AViewInfo.Bounds, cxAlignHCenter);
//计算最多画多少行
lMaxRow := AViewInfo.GridViewInfo.NoDataInfoTextAreaBounds.Bottom - AViewInfo.GridViewInfo.NoDataInfoTextAreaBounds.Top mod AViewInfo.Bounds.Bottom - AViewInfo.Bounds.Top + 2;
if AViewInfo.GridRecord.Index = cxGridDBTableView.ViewData.RecordCount - 1 then
begin
for i := cxGridDBTableView.ViewData.RecordCount + 1 to lMaxRow do
begin
//画表格
Rect1.Top := AViewInfo.Bounds.Top - 1 + (AViewInfo.Bounds.Bottom - AViewInfo.Bounds.Top) * (i - cxGridDBTableView.ViewData.RecordCount);
Rect1.Bottom := AViewInfo.Bounds.Bottom + (AViewInfo.Bounds.Bottom - AViewInfo.Bounds.Top) * (i - cxGridDBTableView.ViewData.RecordCount);
Rect1.Left := AViewInfo.Bounds.Left - 1;
Rect1.Right := AViewInfo.Bounds.Right + 1;
if AViewInfo.GridView.Styles.Content <> nil then
ACanvas.Brush.Color := AViewInfo.GridView.Styles.Content.Color
else
ACanvas.Brush.Color := clWhite;
if (i mod 2) = 0 then
if AViewInfo.GridView.Styles.ContentOdd <> nil then
ACanvas.Brush.Color := AViewInfo.GridView.Styles.ContentOdd.Color
else if AViewInfo.GridView.Styles.ContentEven <> nil then
ACanvas.Brush.Color := AViewInfo.GridView.Styles.ContentEven.Color;
ACanvas.FillRect(Rect1);
ACanvas.Brush.Color := AViewInfo.BorderColor[ABorder];
ACanvas.FrameRect(Rect1);
AViewInfo.GridViewInfo.Painter.ExcludeFromBackground(Rect1);
end;
end;
end;
{-------------------------------------------------------------------------------
作者: 曾聪
日期: 2013.10.07
过程名: IniMyCxGrid
功能: 调用TMyCxGrid相关函数初始化CxGrid
参数:
返回值: 无
说明:
-------------------------------------------------------------------------------}
procedure IniMyCxGrid(cxGridDBTableView: TcxGridDBTableView);
var
MyCxGrid: TMyCxGrid;
begin
MyCxGrid := TMyCxGrid.Create(nil);;
MyCxGrid.cxGridDBTableView := cxGridDBTableView;
if cxGridDBTableView <> nil then
begin
cxGridDBTableView.OnCustomDrawCell := MyCxGrid.CustomDrawCell; //调用自画表格函数
cxGridDBTableView.Site.Cursor := crHandPoint; //改变鼠标手势
end;
end;
end.
procedure TFormMainOperation.FormCreate(Sender: TObject);
begin
IniMyCxGrid(cxgrddbtv1, nil);
end;