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?
Asked
Active
Viewed 3.3k times
3 Answers
14
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.
9
You could try:
DBGrid1.DataSource.DataSet.RecordCount
Maybe there are better solutions. But this worked for me.

Toon Krijthe
- 52,876
- 38
- 145
- 202
-
4TDataSet.RecordCount will often give -1 depending on the situation (like queries). – Lars Truijens Nov 16 '08 at 21:55
-
Thanks, it looks like I have to do some db programming, else I'm losing the touch. (Two years working on a DB less app). – Toon Krijthe Nov 16 '08 at 22:10
-
Indeed, Lars? So much time using TClientDataset, I didn't remember that. What kind of Query objects (ADO, IBX or DBX) show this behavior? I believe dbx would, because it's components are unidirectional cursors - but there are more? – Fabricio Araujo Nov 17 '08 at 17:56