BindingNavigator.BindingSource Özellik

Tanım

Veri kaynağı olan bileşeni alır veya ayarlar BindingSource .

C#
[System.ComponentModel.TypeConverter(typeof(System.ComponentModel.ReferenceConverter))]
public System.Windows.Forms.BindingSource BindingSource { get; set; }

Özellik Değeri

BindingSource

Bu BindingSource BindingNavigatorile ilişkili bileşen. Varsayılan değer: null.

Öznitelikler

Örnekler

Aşağıdaki kod örneği, bir BindingNavigator veri kümesinde hareket etmek için denetimin nasıl kullanılacağını gösterir. Küme, bileşeni olan bir DataViewdenetime bağlı olan içinde TextBox BindingSource bulunur. Bu kod örneği, Nasıl yapılır: Windows Forms BindingNavigator Denetimi ile Bir DataSet İçinde Taşıma bölümünde sağlanan daha büyük bir örneğin parçasıdır.

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(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 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";
        
        using (SqlConnection connection = new SqlConnection(connectString))
        {

            SqlDataAdapter dataAdapter1 = 
                new SqlDataAdapter(new SqlCommand("Select * From Customers",connection));
            DataSet ds = new DataSet("Northwind Customers");
            ds.Tables.Add("Customers");
            dataAdapter1.Fill(ds.Tables["Customers"]);
            
            // Assign the DataSet as the DataSource for the BindingSource.
            this.customersBindingSource.DataSource = ds.Tables["Customers"];

            // Bind the CompanyName field to the TextBox control.
            this.companyNameTextBox.DataBindings.Add(
                new Binding("Text",
                this.customersBindingSource,
                "CompanyName",
                true));
        }
    }

    [STAThread]
    public static void Main()
    {
        Application.EnableVisualStyles();
        Application.Run(new Form1());
    }
}

Açıklamalar

özelliği, BindingSource içinde gezinen BindingNavigator veri kaynağını temsil eder. Daha belirgin olarak, List özelliğinin BindingSource gerçek veri listesini temsil eder.

Bu, sınıfın BindingNavigator varsayılan özelliğidir.

Şunlara uygulanır

Ürün Sürümler
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7

Ayrıca bkz.