Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Change the TStatusBar as the user moves up and down the TDBGrid


This question is answered.


Permlink Replies: 4 - Last Post: Sep 22, 2015 4:37 AM Last Post By: Mister Snrub
Mister Snrub

Posts: 35
Registered: 1/8/12
Change the TStatusBar as the user moves up and down the TDBGrid  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 18, 2015 8:02 AM
I want the status bar to say "Record XX of YYYY" as the user moves to different rows in the TDBGrid, where "XX" is the current record number, and "YYYY" is the total number of records in the dataset. Is there a way to do this?
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Change the TStatusBar as the user moves up and down the TDBGrid
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 18, 2015 9:10 AM   in response to: Mister Snrub in response to: Mister Snrub
Mister wrote:

I want the status bar to say "Record XX of YYYY" as the user moves to
different rows in the TDBGrid, where "XX" is the current record
number, and "YYYY" is the total number of records in the dataset. Is
there a way to do this?

Are you wanting to update the status bar as the user moves the mouse around
the grid, or when the user actually selects a record?

TDBGrid has a MouseCoord() method, which you can call in the OnMouseMove
event, to know which cell is under the mouse.

TDBGrid has a SelectedField property, which you can read in the OnColEnter
event, to know which TField is selected. From that, you can read its DataSet.RecNo
and DataSet.RecordCount properties to get the record number and number of
records, respectively.

--
Remy Lebeau (TeamB)
Mister Snrub

Posts: 35
Registered: 1/8/12
Re: Change the TStatusBar as the user moves up and down the TDBGrid  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 21, 2015 12:46 PM   in response to: Mister Snrub in response to: Mister Snrub
I was referring to when the user actually selects a record, either with the mouse or with the arrow keys. Thanks for your response, but that only works when the user is selecting a cell on a different column from the current one. If the user types the down arrow key, for example, the column index is not changed, therefore the event is not fired.

Edited by: Mister Snrub on Sep 21, 2015 12:46 PM
Paul F

Posts: 6
Registered: 5/22/10
Re: Change the TStatusBar as the user moves up and down the TDBGrid
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 22, 2015 1:45 AM   in response to: Mister Snrub in response to: Mister Snrub
Check TDataSource::OnDataChange
http://docwiki.embarcadero.com/Libraries/XE8/en/Data.DB.TDataSource.OnDataChange

Maybe you can use both (TDBGrid::OnColEnter and TDataSource::OnDataChange)?
Mister Snrub

Posts: 35
Registered: 1/8/12
Re: Change the TStatusBar as the user moves up and down the TDBGrid  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 22, 2015 4:33 AM   in response to: Paul F in response to: Paul F
Paul F wrote:
Check TDataSource::OnDataChange
http://docwiki.embarcadero.com/Libraries/XE8/en/Data.DB.TDataSource.OnDataChange

Maybe you can use both (TDBGrid::OnColEnter and TDataSource::OnDataChange)?

Thank you. It was TDataSource::OnDataChange that did the trick. TDBGrid::OnColEnter was not needed.

void __fastcall TfrMyForm::DataSource1DataChange(TObject *Sender, TField *Field)
{
  try
  {
    TDataSource* dsource = (TDataSource*)Sender;
    TDataSet* dset = dsource->DataSet;
 
    if (dset == NULL)
    {
      LogIt("ERROR: dset is null.");
    }
    else if (dset == 0)
    {
      LogIt("ERROR: dset == 0.");
    }
    else
    {
      StatusBar1->SimpleText = "Record " + String(dset->RecNo) +
        "/" + String(dset->RecordCount);
    }
 
  }
  catch(Exception& e)
  {
    LogIt("ERROR: '" + e.Message + "'");
  }
 
  return;
}
//---------------------------------------------------------------------------
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02