问题
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