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
2008-11-16 20:24:32
TDataSet.RecordCount will often give -1 depending on the situation (like queries).
Lars Truijens
2008-11-16 21:55:06
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
2008-11-16 22:10:44
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
2008-11-17 17:56:00
+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
2008-11-16 20:47:36