如何让DBGrid显示序号?


本文整理自网络,侵删。

 修改GRID.pas
view plaincopy to clipboardprint?
//在TCustomGrid.SetColWidths事件改为:
procedure TCustomGrid.SetColWidths(Index: Longint; Value: Integer);
begin
if FColWidths = nil then
UpdateExtents(FColWidths, ColCount, DefaultColWidth);
if Index >= ColCount then InvalidOp(SIndexOutOfRange);
if Value <> PIntArray(FColWidths)^[Index + 1] then
begin
if Value < 12 then Value := 30; //新增
ResizeCol(Index, PIntArray(FColWidths)^[Index + 1], Value);
PIntArray(FColWidths)^[Index + 1] := Value;
ColWidthsChanged;
end;
end;
//在TCustomGrid.SetColWidths事件改为:
procedure TCustomGrid.SetColWidths(Index: Longint; Value: Integer);
begin
if FColWidths = nil then
UpdateExtents(FColWidths, ColCount, DefaultColWidth);
if Index >= ColCount then InvalidOp(SIndexOutOfRange);
if Value <> PIntArray(FColWidths)^[Index + 1] then
begin
if Value < 12 then Value := 30; //新增
ResizeCol(Index, PIntArray(FColWidths)^[Index + 1], Value);
PIntArray(FColWidths)^[Index + 1] := Value;
ColWidthsChanged;
end;
end;
修改DBGRID.pas
view plaincopy to clipboardprint?
//在procedure TCustomDBGrid.DrawCell事件中找到下面这一行
procedure TCustomDBGrid.DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState);
begin
//...
FIndicators.Draw(Canvas, ALeft,
(ARect.Top + ARect.Bottom - FIndicators.Height) shr 1, Indicator, True);
if ACol <0 then
begin
Canvas.TextRect(ARect,0,(ARect.Top + ARect.Bottom - FIndicators.Height) shr 1 , inttostr(self.DataSource.DataSet.RecNo));
end; //新增
//.....
end;

相关阅读 >>

Delphi常用获取系统信息的函数单元

Delphi 数组与枚举

Delphi 在statusbar1.panels上显示日期时间星期

Delphi 创建win桌面快捷方式,实现360桌面图标数字提示 或 类似安卓的右上角的数字提示

Delphi 两种登录界面验证写法

Delphi中 tstringlist和thashedstringlist的性能对比

Delphi 抓屏技巧

Delphi idhttp访问路由里的web

Delphi窗体自适应分辨率

Delphi反调试【初级】检测法

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...