BindingSource Property

BindingNavigator.BindingSource Property


Gets or sets the System.Windows.Forms.BindingSource component that is the source of data.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public BindingSource BindingSource { get; set; }

Property Value

Type: System.Windows.Forms.BindingSource

The System.Windows.Forms.BindingSource component associated with this BindingNavigator. The default is null.

The BindingSource property represents the data source that the BindingNavigator navigates through. More specifically, the List property of the BindingSource represents the actual data list.

This is the default property for the BindingNavigator class.

The following code example demonstrates how to use a BindingNavigator control to move through a data set. The set is contained in a DataView, which is bound to a TextBox control with a BindingSource component. This code example is part of a larger example provided in How to: Move Through a DataSet with the Windows Forms BindingNavigator Control.

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(true);

    // 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;

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

        // 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";

        using (SqlConnection connection = new SqlConnection(connectString))

            SqlDataAdapter dataAdapter1 = 
                new SqlDataAdapter(new SqlCommand("Select * From Customers",connection));
            DataSet ds = new DataSet("Northwind Customers");

            // Assign the DataSet as the DataSource for the BindingSource.
            this.customersBindingSource.DataSource = ds.Tables["Customers"];

            // Bind the CompanyName field to the TextBox control.
                new Binding("Text",

    public static void Main()
        Application.Run(new Form1());

.NET Framework
Available since 2.0
Return to top
© 2015 Microsoft