Counting the rows in a TDbGrid

…衆ロ難τιáo~ 提交于 2019-12-19 05:53:52

问题


I have a TDbGrid, and I can easily tell how many columns are in it at runtime with the FieldCount property, but there doesn't seem to be a corresponding RowCount property to display how many records are being displayed. How can I find this out?


回答1:


You could try:

DBGrid1.DataSource.DataSet.RecordCount

Maybe there are better solutions. But this worked for me.




回答2:


Both RowCount and VisibleRowCount are protected properties in TCustomGrid that are not exposed in TDBGrid. But you can get round that doing the following:

type
  TDummyGrid = class(TDBGrid);

  RowCount := TDummyGrid(MyDBGrid).RowCount;
  VisibleRowCount := TDummyGrid(MyDBGrid).VisibleRowCount;

Be warned that this includes the header.




回答3:


I would use

TDbGrid.ApproxCount


来源:https://stackoverflow.com/questions/294342/counting-the-rows-in-a-tdbgrid

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!