Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
Previous Versions
.NET Framework 2.0

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
.NET Framework Class Library
BindingNavigator Class

Note: This class is new in the .NET Framework version 2.0.

Represents the navigation and manipulation user interface (UI) for controls on a form that are bound to data.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Visual Basic (Declaration)
<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
Public Class BindingNavigator
    Inherits ToolStrip
    Implements ISupportInitialize
Visual Basic (Usage)
Dim instance As BindingNavigator
C#
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
public class BindingNavigator : ToolStrip, ISupportInitialize
C++
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] 
public ref class BindingNavigator : public ToolStrip, ISupportInitialize
J#
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
public class BindingNavigator extends ToolStrip implements ISupportInitialize
JScript
ComVisibleAttribute(true) 
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
public class BindingNavigator extends ToolStrip implements ISupportInitialize

The BindingNavigator control represents a standardized way to navigate and manipulate data on a form. In most cases, a BindingNavigator is paired with a BindingSource control to move through data records on a form and interact with them. In these cases, the BindingSource property is set to the associated System.Windows.Forms.BindingSource component that acts as a data source.

By default, the BindingNavigator control's user interface (UI) is composed of a series of ToolStrip buttons, text boxes, and static text elements for most common data-related actions, such as adding data, deleting data, and navigating through data. Each of these controls can be retrieved or set through an associated member of the BindingNavigator control. Likewise, there is also a one-to-one correspondence to members within the BindingSource class that programmatically perform the same functionality, as shown in the following table.

UI Control

BindingNavigator member

BindingSource member

Move First

MoveFirstItem

MoveFirst

Move Previous

MovePreviousItem

MovePrevious

Current Position

PositionItem

Current

Count

CountItem

Count

Move Next

MoveNextItem

MoveNext

Move Last

MoveLastItem

MoveLast

Add New

AddNewItem

AddNew

Delete

DeleteItem

RemoveCurrent

Adding a BindingNavigator control to a form and binding it to a data source, such as a BindingSource, will automatically establish the relationships in this table.

All the constructors for BindingNavigator call the AddStandardItems method to associate the standard set of UI controls with the navigation toolbar. Use one of the following techniques to customize this toolbar:

  • Create the BindingNavigator with the BindingNavigator(Boolean) constructor, which accepts a Boolean addStandardItems parameter, and set this parameter to false. Then add the desired ToolStripItem objects to the Items collection.

  • If a great deal of customization is desired, or the custom design will be reused, derive a class from BindingNavigator and override the AddStandardItems method to define additional or alternate standard items.

The following code example demonstrates how to use a BindingNavigator control to move through the results of a database query. The result set is contained in a DataSet, which is bound to a TextBox control with a BindingSource component.

Visual Basic
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Data.SqlClient
Imports System.Windows.Forms

' This form demonstrates using a BindingNavigator to display 
' rows from a database query sequentially.
Public Class Form1
    Inherits Form

    ' This is the BindingNavigator that allows the user
    ' to navigate through the rows in a DataSet.
    Private customersBindingNavigator As New BindingNavigator()

    ' This is the BindingSource that provides data for
    ' the Textbox control.
    Private customersBindingSource As New BindingSource()

    ' This is the TextBox control that displays the CompanyName
    ' field from the the DataSet.
    Private companyNameTextBox As New TextBox()

    Public Sub New()
        ' Set up the BindingSource component.
        Me.customersBindingNavigator.BindingSource = Me.customersBindingSource
        Me.customersBindingNavigator.Dock = DockStyle.Top
        Me.Controls.Add(Me.customersBindingNavigator)

        ' Set up the TextBox control for displaying company names.
        Me.companyNameTextBox.Dock = DockStyle.Bottom
        Me.Controls.Add(Me.companyNameTextBox)

        ' Set up the form.
        Me.Size = New Size(800, 200)
        AddHandler Me.Load, AddressOf Form1_Load
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)

        ' Open a connection to the database.
        ' Replace the value of connectString with a valid 
        ' connection string to a Northwind database accessible 
        ' to your system.
        Dim connectString As String = _
        "Integrated Security=SSPI;Persist Security Info=False;" + _
        "Initial Catalog=Northwind;Data Source=localhost"

        Dim connection As New SqlConnection()
        connection.ConnectionString = connectString
        connection.Open()

        ' Execute the query.
        Dim command As New SqlCommand( _
        "Select * From Customers", connection)

        Dim reader As SqlDataReader = _
        command.ExecuteReader(CommandBehavior.CloseConnection)

        ' Load the Customers result set into the DataSet.
        Dim ds As New DataSet("Northwind Customers")
        ds.Load( _
        reader, _
        LoadOption.OverwriteChanges, _
        New String() {"Customers"})

        ' Assign the DataSet as the DataSource for the BindingSource.
        Me.customersBindingSource.DataSource = ds

        ' Bind the CompanyName field to the TextBox control.
        Me.companyNameTextBox.DataBindings.Add( _
        New Binding( _
        "Text", _
        Me.customersBindingSource, _
        "CompanyName", _
        True))
    End Sub

End Class
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Data.SqlClient;
using System.Windows.Forms;

// This form demonstrates using a BindingNavigator to display 
// rows from a database query sequentially.
public class Form1 : Form
{
    // This is the BindingNavigator that allows the user
    // to navigate through the rows in a DataSet.
    BindingNavigator customersBindingNavigator = new BindingNavigator();

    // This is the BindingSource that provides data for
    // the Textbox control.
    BindingSource customersBindingSource = new BindingSource();

    // This is the TextBox control that displays the CompanyName
    // field from the the DataSet.
    TextBox companyNameTextBox = new TextBox();

    public Form1()
    {
        // Set up the BindingSource component.
        this.customersBindingNavigator.BindingSource = this.customersBindingSource;
        this.customersBindingNavigator.Dock = DockStyle.Top;
        this.Controls.Add(this.customersBindingNavigator);

        // Set up the TextBox control for displaying company names.
        this.companyNameTextBox.Dock = DockStyle.Bottom;
        this.Controls.Add(this.companyNameTextBox);

        // Set up the form.
        this.Size = new Size(800, 200);
        this.Load += new EventHandler(Form1_Load);
    }

    void Form1_Load(object sender, EventArgs e)
    {   
        // Open a connection to the database.
        // Replace the value of connectString with a valid 
        // connection string to a Northwind database accessible 
        // to your system.
        string connectString = 
            "Integrated Security=SSPI;Persist Security Info=False;" +
            "Initial Catalog=Northwind;Data Source=localhost";
        SqlConnection connection = new SqlConnection();
        connection.ConnectionString = connectString;
        connection.Open();

        // Execute the query.
        SqlCommand command = new SqlCommand(
            "Select * From Customers", connection);
        SqlDataReader reader = command.ExecuteReader(
            CommandBehavior.CloseConnection);

        // Load the Customers result set into the DataSet.
        DataSet ds = new DataSet("Northwind Customers");
        ds.Load(
            reader, 
            LoadOption.OverwriteChanges, 
            new string[] { "Customers" });

        // Assign the DataSet as the DataSource for the BindingSource.
        this.customersBindingSource.DataSource = ds;

        // Bind the CompanyName field to the TextBox control.
        this.companyNameTextBox.DataBindings.Add(
            new Binding("Text", 
            this.customersBindingSource, 
            "CompanyName", 
            true));
    }
}
C++
#using <System.dll>
#using <System.Data.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
#using <System.EnterpriseServices.dll>
#using <System.Transactions.dll>
#using <System.Xml.dll>

using namespace System;
using namespace System::Collections::Generic;
using namespace System::ComponentModel;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Data::SqlClient;
using namespace System::Windows::Forms;

// This form demonstrates using a BindingNavigator to display
// rows from a database query sequentially.
public ref class Form1 : public Form
{
    // This is the BindingNavigator that allows the user
    // to navigate through the rows in a DataSet.
    BindingNavigator^ customersBindingNavigator;

    // This is the BindingSource that provides data for
    // the Textbox control.
    BindingSource^ customersBindingSource;

    // This is the TextBox control that displays the CompanyName
    // field from the the DataSet.
    TextBox^ companyNameTextBox;

public:
    Form1()
    {
        // Set up the BindingSource component.
        this->customersBindingSource = gcnew BindingSource();
        this->companyNameTextBox = gcnew TextBox();
        this->customersBindingNavigator = gcnew BindingNavigator();
        this->customersBindingNavigator->BindingSource =
            this->customersBindingSource;
        this->customersBindingNavigator->Dock = DockStyle::Top;
        this->Controls->Add(this->customersBindingNavigator);

        // Set up the TextBox control for displaying company names.
        this->companyNameTextBox->Dock = DockStyle::Bottom;
        this->Controls->Add(this->companyNameTextBox);

        // Set up the form.
        this->Size = System::Drawing::Size(800, 200);
        this->Load += gcnew EventHandler(this, &Form1::Form1_Load);
    }

private:
    void Form1_Load(Object^ sender, EventArgs^ e)
    {
        // Open a connection to the database.
        // Replace the value of connectString with a valid
        // connection string to a Northwind database accessible
        // to your system.
        String^ connectString =
            "Integrated Security=SSPI;Persist Security Info=False;" +
            "Initial Catalog=Northwind;Data Source=localhost";
        SqlConnection^ connection = gcnew SqlConnection();
        connection->ConnectionString = connectString;
        connection->Open();

        // Execute the query.
        SqlCommand^ command = gcnew SqlCommand(
            "Select * From Customers", connection);
        SqlDataReader^ reader = command->ExecuteReader(
            CommandBehavior::CloseConnection);

        // Load the Customers result set into the DataSet.
        DataSet^ ds = gcnew DataSet("Northwind Customers");
        ds->Load(reader, LoadOption::OverwriteChanges,
            gcnew array<String^> {"Customers"});

        // Assign the DataSet as the DataSource for the
        // BindingSource.
        this->customersBindingSource->DataSource = ds->Tables[0];

        // Bind the CompanyName field to the TextBox control.
        this->companyNameTextBox->DataBindings->Add(gcnew Binding("Text",
            this->customersBindingSource, "CompanyName", true));
    }
};
System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Windows.Forms.Control
         System.Windows.Forms.ScrollableControl
           System.Windows.Forms.ToolStrip
            System.Windows.Forms.BindingNavigator
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker