9

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?

Mason Wheeler
  • 82,511
  • 50
  • 270
  • 477

3 Answers3

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.

bluish
  • 26,356
  • 27
  • 122
  • 180
Steve
  • 6,382
  • 3
  • 41
  • 66
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
  • 4
    TDataSet.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
1

I would use

TDbGrid.ApproxCount
bluish
  • 26,356
  • 27
  • 122
  • 180
hassen
  • 11
  • 1