TFdbgrid=class(Tdbgrid)
protected
procedure SetColumnAttributes; override;
procedure DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState); override;
end;
procedure TFdbgrid.DrawCell(ACol, ARow: Integer; ARect: TRect;
AState: TGridDrawState);
var Ftoprow,i:Integer;
function gettoprow:Integer;
var i:Integer;
SInfo: TScrollInfo;
begin
for i:=0 to RowCount-1 do
begin
if DataLink.ActiveRecord=i then
begin
SInfo.cbSize := sizeof(SInfo);
SInfo.fMask := SIF_ALL;
GetScrollInfo(self.Handle, SB_VERT, SInfo);
if (DataLink.DataSet.State =dsInsert) and (DataLink.ActiveRecord=DataLink.BufferCount-1 ) then
begin
result:=SInfo.nPos-i+1;
end else
result:=SInfo.nPos-i;
if Result=0 then Result:=1;
Break;
end;
end;
end;
begin
if (ACol <= 0) then
begin
Canvas.Brush.Color := FixedColor;
Canvas.FillRect(ARect);
Ftoprow:=gettoprow-1;
if (ARow>0) then
Canvas.TextRect(ARect, 1, ARect.Top + 5, IntToStr(Arow+Ftoprow));
end else
inherited
end;
procedure TFdbgrid.SetColumnAttributes;
begin
inherited;
if (dgIndicator in Options) then
ColWidths[0] := 30;
end;
高手测试一下。我在本机上用BDE、ADO测试,滚动、新增、插入、删除操作暂时没发现问题