RAD Studio |  |

Choosing Navigator Buttons to Display
Hiding and showing navigator buttons at design time | Hiding and showing navigator buttons at runtime | See Also
Collapse All

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 runtime

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 of which permits users to edit records, and the other of which is read-only. When you switch between datasets, you want to hide the navigator's Insert, Delete, Edit, Post, Cancel, and Refresh buttons 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's one way you might code the event handler:

Copy Code

    procedure TForm1.CustomerCompanyEnter(Sender :TObject);
    begin
      if Sender = CustomerCompany then
      begin
        DBNavigatorAll.DataSource := CustomerCompany.DataSource;
        DBNavigatorAll.VisibleButtons := [nbFirst,nbPrior,nbNext,nbLast];
      end
      else
      begin
        DBNavigatorAll.DataSource := OrderNum.DataSource;
        DBNavigatorAll.VisibleButtons := DBNavigatorAll.VisibleButtons + [nbInsert,
          nbDelete,nbEdit,nbPost,nbCancel,nbRefresh];
      end;
    end;

For a C++ 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's one way you might code the event handler:

Copy Code

    void __fastcall TForm1::CustomerCompanyEnter(TObject *Sender)
    {
      if (Sender == (TObject *)CustomerCompany)
      {
        DBNavigatorAll->DataSource = CustomerCompany->DataSource;
        DBNavigatorAll->VisibleButtons = DBNavigatorAll->VisibleButtons
    << nbFirst << nbPrior << nbNext << nbLast;
      }
      else
      {
        DBNavigatorAll->DataSource = OrderNum->DataSource;
        DBNavigatorAll->VisibleButtons = DBNavigatorAll->VisibleButtons << nbInsert
    << nbDelete << nbEdit
    << nbPost << nbCancel << nbRefresh;
      }
    }

See Also

Displaying Fly-over Help

Using a Single Navigator for Multiple Datasets

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!