不好意思~~现在才回复~~以下是网上Dbgrid的,我已经改为DBGRIDEH测试通过~var di:integer;//全局变量 bflag,bflag2:boolean; //全局变量procedure Tfm1.ds1StateChange(Sender: TObject);//数据库的StateChangebegin if dbgrideh1.DataSource.DataSet.State <>dsbrowse then begin di:=dbgrideh1.DataSource.DataSet.RecordCount+3 -TDrawGrideh(DBgrideh1).RowCount ; bflag := true; end else bflag:=false;end;procedure Tfm1.DBGridEh1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumnEh; State: TGridDrawState);var rect1:TRect; sValue :string; ss:boolean; begin if DataCol = 0 then //設置在第一列 begin if DBGridEH1.DataSource.DataSet.state<>dsInsert then di:= DBGridEH1.DataSource.DataSet.recno; Rect1 := Rect; with DBGridEH1 do begin Canvas.Brush.Color:=clBtnFace; sValue:=IntToStr(di); Canvas.FillRect(Rect1); Canvas.Pen.Width:=1; Canvas.Pen.Color:=clWhite; Canvas.MoveTo(Rect1.Left,Rect1.Bottom); Canvas.LineTo(Rect1.Left,Rect1.Top); Canvas.LineTo(Rect1.right,Rect1.Top); Canvas.Pen.Color:=clBtnShadow; Canvas.LineTo(Rect1.right,Rect1.Bottom-1); Canvas.LineTo(Rect1.Left,Rect1.Bottom-1); Rect1.Top:=Rect1.Top+1; if State=[gdSelected,gdFocused] then begin if bflag=true then begin sValue:=inttostr(datasource.DataSet.RecordCount+1); di:=datasource.DataSet.RecordCount +1; ss:=true; end; Canvas.Font.Color := clred; end else begin Canvas.Font.Color := clgreen; end; DrawText(Canvas.Handle,PChar(sValue),Length(sValue),Rect1,DT_CENTER); end; if di<=DBGridEH1.DataSource.DataSet.RecordCount then begin inc(di); end else begin if (ss<>true) then di:=DBGridEH1.DataSource.DataSet.RecordCount+3 -TDrawGrid(DBGridEH1).RowCount ; end; end else bflag2:=false;end;procedure Tfm1.DBGridEh1ColEnter(Sender: TObject);beginif (bflag=true)and (dbgrideh1.SelectedField.FieldNo <>1) then begin di:=dbgrideh1.DataSource.DataSet.RecordCount+3-Tdbgrideh(dbgrideh1).RowCount; dbgrideh1.Refresh; end; end;procedure Tfm1.DBGridEh1ColExit(Sender: TObject);begin if (bflag=true)and (dbgrideh1.SelectedField.FieldNo =1) then begin di:=dbgrideh1.DataSource.DataSet.RecordCount+1; dbgrideh1.Refresh; end;end;