views:

1399

answers:

3

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?

+2  A: 

You could try:

DBGrid1.DataSource.DataSet.RecordCount

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

Gamecat
TDataSet.RecordCount will often give -1 depending on the situation (like queries).
Lars Truijens
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).
Gamecat
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
+5  A: 

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.

Steve
A: 

TDbGrid.ApproxCount

hassen