Choosing Navigator Buttons to Display

From RAD Studio
Jump to: navigation, search

Go Up to Navigating and Manipulating Records

When you first place a TDBNavigator on a form at design time, all its buttons are visible. You can use the VisibleButtons property to turn off buttons you do not want to use on a form. For example, when working with a unidirectional dataset, only the First, Next, and Refresh buttons are meaningful. On a form that is intended for browsing rather than editing, you might want to disable the Edit, Insert, Delete, Post, and Cancel buttons.

Hiding and showing navigator buttons at design time

The VisibleButtons property in the Object Inspector is displayed with a + sign to indicate that it can be expanded to display a Boolean value for each button on the navigator. To view and set these values, click on the + sign. The list of buttons that can be turned on or off appears in the Object Inspector below the VisibleButtons property. The + sign changes to a - (minus) sign, which you can click to collapse the list of properties.

Button visibility is indicated by the Boolean state of the button value. If a value is set to True, the button appears in the TDBNavigator. If False, the button is removed from the navigator at design time and runtime.

Note: As button values are set to False, they are removed from the TDBNavigator on the form, and the remaining buttons are expanded in width to fill the control. You can drag the control's handles to resize the buttons.

Hiding and showing navigator buttons at run time

At runtime you can hide or show navigator buttons in response to user actions or application states. For example, suppose you provide a single navigator for navigating through two different datasets: one allows users to edit records, and the other one is read-only. When you switch between datasets, you want to hide the Insert, Delete, Edit, Post, Cancel, and Refresh buttons of the navigator for the read-only dataset, and show them for the other dataset.

For example, suppose you want to prevent edits to the OrdersTable by hiding the Insert, Delete, Edit, Post, Cancel, and Refresh buttons on the navigator, but that you also want to allow editing for the CustomersTable. The VisibleButtons property controls which buttons are displayed in the navigator. Here is one way you might code the event handler:

 procedure TForm1.CustomerCompanyEnter(Sender :TObject);
   if Sender = CustomerCompany then
     DBNavigatorAll.DataSource := CustomerCompany.DataSource;
     DBNavigatorAll.VisibleButtons := [nbFirst,nbPrior,nbNext,nbLast];
     DBNavigatorAll.DataSource := OrderNum.DataSource;
     DBNavigatorAll.VisibleButtons := DBNavigatorAll.VisibleButtons + [nbInsert,

See Also