版主,打扰了,实在是找不到很好的方法的联系你了,所以只有借此打扰你了,望谅!我在12日在论坛里提出下面的问题.并得到你的答案.可我的问题还是没有解决,很急!!所以打扰你了!如何在dbgrideh第一列中显示行号??? procedure TFMOutsstorage.ADODataSet1FnoGetText(Sender: TField; var Text: String; DisplayText: Boolean);begin text:=inttostr(ADODataSet1.RecNo);end;我是在ADODataSet1中新增了一个虚字段Fno ,这样可以显示行号,但每次按向下箭头新增纪录时 总是所有行号纪录均变成-1, 当重点击上一条记录时,行号又正常显示了! !!! OnDrawColumnCell事件中 begin if Column.Index=0 then with DBGridEH1.Canvas do begin FillRect(Rect); TextOut(Rect.Left+2,Rect.Top+2,IntToStr(DBGridEH1.DataSource.DataSet.RecNo)); end; end;
不好意思~~现在才回复~~以下是网上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;