Export (0) Print
Expand All

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)

'Declaration
<TypeConverterAttribute(GetType(ReferenceConverter))> _
Public Property BindingSource As BindingSource

Property Value

Type: System.Windows.Forms.BindingSource
The System.Windows.Forms.BindingSource component associated with this BindingNavigator. The default is Nothing.

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.

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(True)

    ' 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 'New 


    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(connectString)
        Try 

            Dim dataAdapter1 As New SqlDataAdapter( _
                New SqlCommand("Select * From Customers", connection))
            Dim ds As New DataSet("Northwind Customers")
            ds.Tables.Add("Customers")
            dataAdapter1.Fill(ds.Tables("Customers"))

            ' Assign the DataSet as the DataSource for the BindingSource. 
            Me.customersBindingSource.DataSource = ds.Tables("Customers")

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

    End Sub 'Form1_Load


    <STAThread()> _
    Public Shared Sub Main()
        Application.EnableVisualStyles()
        Application.Run(New Form1())

    End Sub 
End Class

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft