Home

Database Visual Support: The Binding Navigator

 

Introduction

If you drag a table from the Data Source window and drop it on a form, Microsoft Visual Studio adds the necessary Windows controls to the form and binds them to the columns of the table. To move from one record to another, you would need a way to navigate among the records. You can manually take care of this if you want. Alternatively, the .NET Framework provides a class named BindingNavigator that contains all the necessary functionality for this task.

 

Creating a Binding Navigator

There are various ways you can create a binding navigator:

  • You can declare a variable of type BindingNavigator and configure it
  • From the Data section of the Toolbox, you can drag a BindingNavigator object and drop it on a form. You should then access the Properties window for the binding navigator. To support this, the BindingNavigator class has a property named BindingSource. You can access it from the Properties window of the binding navigator and select the binding source
  • If you drag a table from the Data Source window and drop it on a form, Microsoft Visual Studio would create and configure a binding navigator for you

Practical Learning Practical Learning: Creating a Binding Navigator

  1. In the Data section of the Toolbox, click BindingNavigator and click the form
  2. In the Properties window, change its Name to bnRentalProperties
  3. Still in the Properties window, click BindingSource and select bsSolasPropertyRental
  4. In the Data section of the Toolbox, click DataGridView and click the form
  5. Still in the Properties window, click DataSource and select bsSolasPropertyRental
  6. Under the Properties window, click Edit Columns and configure the columns as follows:
     
    Column HeaderText Width
    RentalPropertyID Prop ID 50
    PropertyCode Prop Code 70
    PropertyType Property Type 90
    Bedrooms Beds 50
    Bathrooms Baths 50
    MonthlyRent Monthly Rent 80
    OccupancyStatus Status 90
  7. In the Properties window, change the following characteristics:
    (Name): dgvRentalProperties
    ColumnHeadersHeightSizeMode: EnableResizing
     
    Solas Property Rental
  8. Execute the application to see the result

    Solas Property Rental - Properties Listing
  9. Close the form and return to your programming environment

Published on Friday 04 January 2008


Previous Copyright © 2007 FunctionX, Inc. Next