RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TDBNavigator Class

TDBNavigator (the database navigator) is used to move through the data in a dataset and perform operations on the data, such as inserting a blank record or posting a record.

Pascal
TDBNavigator = class(TCustomPanel);
C++
class TDBNavigator : public TCustomPanel;

DBCtrls

Use the database navigator on forms that contain data-aware controls, such as TDBGrid or TDBEdit. TDBNavigator lets the user control the dataset when editing or viewing the data. 

When the user chooses one of the navigator buttons, the appropriate action occurs on the dataset to which the navigator is linked. For example, if the user clicks the Insert button, a blank record is inserted in the dataset. 

TDBNavigator can show any or all of the following buttons:

Button 
Purpose 
First  
Sets the current record to the first record in the dataset, disables the First and Prior buttons, and enables the Next and last buttons if they are disabled.  
Prior  
Sets the current record to the previous record and enables the Last and Next buttons if they are disabled.  
Next  
Sets the current record to the next record and enables the First and Prior buttons if they are disabled.  
Last  
Sets the current record to the last record in the dataset, disables the Last and Next buttons, and enables the First and Prior buttons if they are disabled.  
Insert  
Inserts a new record before the current record, and sets the dataset into Insert and Edit states.  
Delete  
Deletes the current record and makes the next record the current record.  
Edit  
Puts the dataset into Edit state so that the current record can be modified.  
Post  
Writes changes in the current record to the database.  
Cancel  
Cancels edits to the current record, restores the record display to its condition prior to editing, and turns off Insert and Edit states if they are active.  
Refresh  
Refreshes the buffered data in the associated dataset.  

 

Delphi Examples: 

{
This example requires two ClientDataSets, two DBGrids, two
DataSources and two DBNavigators.  Name the two
ClientDataSets CDS and CDS2. Set the DataSet property in the
first DataSource to CDS and name that DataSource DS.  Set the
DataSet property in the second DataSource to CDS2 and name
that DataSource DS2.  Set the DataSource in the first
DBNavigator to DS and the DataSource in the second DBNavigator
to DS2.  Set the DataSource in the first DBGrid to DS and the
DataSource in the second DBGrid to DS2.  Right click on CDS
and select the Fields Editor, then right click on the Field
Editor form and create two fields by selecting "new field".
In the field configuration window, set the name to HOST, the
Component value will automatically be set to CDSHOST.  Set
the filed type to String.  In the field configuration window
for the second field, set the name to PORTA, the Component
value will automatically be set to CDSPORTA.  Set the field
type to Integer.  The file used to load CDS must have an
attribute name of HOST with an attribute type of string and
an attribute name of PORTA with an attribute type of integer.
Add DB, DBCtrls, Grids, DBGrids, DBClient and SwSystem to the
uses clause.  "LoadFormFile" to start with the file, or 
"CreateDataSet" to start from scratch.  You must "CloseDataSet"
after a "LoadFromFile" before you can do another "CreateDataSet".
}
procedure TForm1.Button1Click(Sender: TObject);
begin
  CDS.LoadFromFile(gsAppPath + 'CDS.XML');
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  CDS.SaveToFile(gsAppPath + 'CDS.XML', dfXML);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  CDS.CreateDataSet;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  CDS2.Data := CDS.Data;
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
  CDS.Close;
end;

 

TDataSource 

TDataSet 

TDBGrid 

TDBEdit 

Choosing How to Organize the Data 

Choosing Navigator Buttons to Display 

Enabling Editing in Controls On User Entry 

Using Common Data Control Features 

Navigating and Manipulating Records 

Using the First and Last Methods 

Navigating Datasets

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!