SaveLog('设置显示格式时出错:' + E.Message); end; end;
**************************************************************************** 62 给cxGRID加序号列 解决:
procedure SetRowNumber(var ASender: TcxGridTableView; AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ACanvas: TcxCanvas; var ADone: boolean); uses cxLookAndFeelPainters;
procedure SetRowNumber(var ASender: TcxGridTableView; AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ACanvas: TcxCanvas; var ADone: boolean); var
AIndicatorViewInfo: TcxGridIndicatorRowItemViewInfo; ATextRect: TRect; AFont: TFont;
AFontTextColor, AColor: TColor; begin
AFont := ACanvas.Font; AColor := clBtnFace;
AFontTextColor := clWindowText ;
if (AViewInfo is TcxGridIndicatorHeaderItemViewInfo) then begin ATextRect := AViewInfo.Bounds; InflateRect(ATextRect, -1, -1);
ASender.LookAndFeelPainter.DrawHeader(ACanvas, AViewInfo.Bounds, ATextRect, [], cxBordersAll, cxbsNormal, taCenter, vaCenter, False, False, '序号', AFont, AFontTextColor, AColor); ADone := True; end ;
if not (AViewInfo is TcxGridIndicatorRowItemViewInfo) then Exit;
ATextRect := AViewInfo.ContentBounds;
AIndicatorViewInfo := AViewInfo as TcxGridIndicatorRowItemViewInfo; InflateRect(ATextRect, -1, -1);
ASender.LookAndFeelPainter.DrawHeader(ACanvas, AViewInfo.ContentBounds, ATextRect, [], [bBottom, bLeft, bRight], cxbsNormal, taCenter, vaCenter, False, False, IntToStr(AIndicatorViewInfo.GridRecord.Index + 1), AFont, AFontTextColor, AColor); ADone := True;
ASender.LookAndFeelPainter.DrawIndicatorImage(ACanvas,ATextRect, AIndicatorViewInfo.IndicatorKind); end;
如果你不要行标志的话,你可以不改控件
直接注释掉这一行: ASender.LookAndFeelPainter.DrawIndicatorImage(ACanvas, ATextRect, AIndicatorViewInfo.IndicatorKind); 要标志的话,在DrawIndicatorImage 从这里跟进去(Ctrl+左键单击) 在 cxLookAndFeelPainters 单元中作如下修改:
class procedure TcxCustomLookAndFeelPainter.DrawIndicatorImage(ACanvas: TcxCanvas; const R: TRect; AKind: TcxIndicatorKind); var
X, Y: Integer; begin
if AKind = ikNone then Exit; with cxIndicatorImages, R do begin
X := (Left + Right - Width); //靠右 Y := (Top + Bottom - Height) div 2; //居中 end;
cxIndicatorImages.Draw(ACanvas.Canvas, X, Y, Ord(AKind) - 1); end;
注意,我已注明靠右的那一行, 就是去掉 DIV 2 了, 还要改一个地方:
SKIN控件目录下的dxSkinLookAndFeelPainter单元,找到 TdxSkinLookAndFeelPainter.DrawIndicatorImage 函数 的
OffsetRect(ARect, (Left + Right - cx div 2) , (Top + Bottom - cy) div 2);
这一行,将 (Left + Right - cx div 2) 改为(Left + Right - cx) 也是去掉 div 2 就是靠右; 修改后: OffsetRect(ARect, (Left + Right - cx) , (Top + Bottom - cy) div 2); 使用
procedure TForm1.cxGrid1DBTableView1CustomDrawIndicatorCell( Sender: TcxGridTableView; ACanvas: TcxCanvas;
AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ADone: Boolean); begin
SetRowNumber(Sender,AviewInfo,ACanvas,ADone); end;
另外序号列的列宽最好改为25以上! 效果图:
****************************************************************************
63 cxGrid自带过滤后数据也数据集同步 解决:
在cxGrid的View Filter事件的OnBeforeChange中写代码就可以了. procedure
TForm1.tvcxgd1DBTableView1DataControllerFilterBeforeChange( Sender: TcxDBDataFilterCriteria; ADataSet: TDataSet; const AFilterText: String); begin //这里可以增加数据集控件的filter:=false; //如:
adoquery.filter:=false; //如果使用的是cxgrid的汉化版本,可以将
AFilterText中的中文等于,小于 替换成 = <等 //adoquery.filter:=替换了中文的AFilterText; ShowMessage(AFilterText); end; 写了上述步骤后可以在tvcxgd1DBTableView1DataControllerFilterChanged写
adoquery.filter:=true; 这样就起到了cxgrid过滤后的数据同步到adoquery
百度搜索“70edu”或“70教育网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,70教育网,提供经典综合文库delphi控件cxGrid用法大全(7)在线全文阅读。
相关推荐: