如何在dbgrideh第一列中显示行号???(50)

  • 主题发起人 主题发起人 chenp1688
  • 开始时间 开始时间
C

chenp1688

Unregistered / Unconfirmed
GUEST, unregistred user!
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;
 
新版的就带有这功能了,不过要数据集支持
 
de410我按你的方法做了,可是还是没有解决,是不是还有其他的属性需要设置,望指教!
 
双击DBGRIDEH1 Columns Editor 新建一个cloumn title caption: ''序号''DBGRIDEH1 DrawColumnCell事件中添加这个就是你要的效果,不需要增加虚字段。当然那个也是一个方法。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;
 
接受答案了.
 
后退
顶部