<< Return to Main Index

< Return to Class Index

CGXBrowserGrid::OnGetRecordCount

virtual long OnGetRecordCount();

Return Value

A long number with the record count.

Remarks

This method is called to determine the number of records. If the record count is unknown, the method should return LONG_MAX.

ODBC and DAO specific-> If you know the exact record count in advance (maybe by using a "SELECT COUNT(*)"), you can override this method and return the record count. ->End

Note: If you want to be sure that a subsequent call to OnGetRecordCount will return the exact record count you should call

   OnTestGridDimension(GX_MAXROWCOL, 0);

before calling OnGetRecordCount.

You should override this method to bind the grid to your external data source. If you know the exact record count, you should determine this value from your data source and return it. If you do not know the record count in advance, you may consider providing a high-water mark the same way as CGXDaoGrid and CGXODBCGrid implement it.

CGXBrowsParam has a data member m_nRecordLastSeen. If you return LONG_MAX, the grid will use m_nRecordLastSeen for estimating the record count. If you want to add support for estimating the record count with your data source, you should take a look at the CGXDaoGrid implementation of the methods OnTestGridDimension and OnGetRecordCount. OnTestGridDimension should be responsible for increasing the m_nRecordLastSeen attribute when the user loops through the records.

Example

This example shows you two scenarios:

a) CGXDaoGrid implementation using a high-water mark for the record count:

long CGXDaoGrid::OnGetRecordCount()
{
   CGXBrowseParam* pBrowseData = GetBrowseParam();

   if (!m_pRecordset->IsOpen())
      return 0;

   // check if record count is known
   if (pBrowseData->m_bEOFSeen)
      return pBrowseData->m_nRecordLastSeen+1;

   // last record has not been seen yet, record count is unknown
   return LONG_MAX;
}

b) Used with an external data source where the record count is known (as in the DbfBrows sample):

long CDbfBrowserView::OnGetRecordCount()
{
   // return rows in dbase file (we know exact record count)
   return GetDocument()->m_dbfile.nRecordCount;
}

CGXBrowserGrid

Class Overview | Class Members