简体   繁体   中英

Counting the rows in a TDbGrid

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?

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.

You could try:

DBGrid1.DataSource.DataSet.RecordCount

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

我会用

TDbGrid.ApproxCount

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM