クリックして評価とフィードバックをお寄せください
MSDN
MSDN ライブラリ
.NET 開発
.NET Framework 3.5
.NET Framework
System.Windows.Forms 名前空間
BindingNavigator クラス
このページは次のバージョンについて記述しています。
Microsoft Visual Studio 2008/.NET Framework 3.5

その他のバージョンについては、以下の情報を参照してください。
.NET Framework クラス ライブラリ
BindingNavigator クラス

更新 : 2007 年 11 月

フォーム上にあるデータにバインドされたコントロールの移動および操作用ユーザー インターフェイス (UI) を表します。

名前空間 :  System.Windows.Forms
アセンブリ :  System.Windows.Forms (System.Windows.Forms.dll 内)

Visual Basic (宣言)
<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
Public Class BindingNavigator _
    Inherits ToolStrip _
    Implements ISupportInitialize
Visual Basic (使用法)
Dim instance As BindingNavigator
C#
[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
public class BindingNavigator : ToolStrip, 
    ISupportInitialize
Visual 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
public class BindingNavigator extends ToolStrip implements ISupportInitialize

BindingNavigator コントロールは、フォーム上のデータ間を移動したり、データを操作したりするための標準的な方法を表します。多くの場合、BindingNavigator は、BindingSource コントロールと組み合わせて、フォーム上のデータ レコード間を移動したり、レコードを操作したりするために使用します。この場合、BindingSource プロパティが、データ ソースとして機能する関連の System.Windows.Forms..::.BindingSource コンポーネントに設定されます。

既定では、BindingNavigator コントロールのユーザー インターフェイス (UI) は、一連の ToolStrip ボタン、テキスト ボックス、および最もよく使用されるデータ関連操作 (データの追加、データの削除、データ間の移動など) を表す静的テキスト要素で構成されます。これらの各コントロールは、BindingNavigator コントロールの関連するメンバを通じて取得または設定できます。また、これらのメンバは、プログラム上で同じ機能を果たす BindingSource クラスのメンバと一対一で対応しています。次の表に、その対応を示します。

UI コントロール

BindingNavigator のメンバ

BindingSource のメンバ

最初に移動

MoveFirstItem

MoveFirst

前に戻る

MovePreviousItem

MovePrevious

現在の場所

PositionItem

Current

Count

CountItem

Count

次に移動

MoveNextItem

MoveNext

最後に移動

MoveLastItem

MoveLast

新規追加

AddNewItem

AddNew

Delete

DeleteItem

RemoveCurrent

BindingNavigator コントロールをフォームに追加して、BindingSource などのデータ ソースにバインドすると、このテーブルの関係が自動的に確立されます。

このツール バーをカスタマイズするには、次の方法のうちいずれかを使用します。

  • ブール値の addStandardItems パラメータを取る BindingNavigator(Boolean) コンストラクタを使用し、このパラメータを false に設定して、BindingNavigator を作成します。次に、目的の ToolStripItem オブジェクトを Items コレクションに追加します。

  • 大幅なカスタマイズを行う場合、またはカスタム デザインを再利用する場合は、BindingNavigator からクラスを派生させ、AddStandardItems メソッドをオーバーライドして、標準項目を追加するか、代わりの標準項目を定義します。

BindingNavigator コントロールを使用してデータセット間を移動する方法を次のコード例に示します。セットは、DataView に含まれます。これは BindingSource コンポーネントと共に TextBox コントロールにバインドされています。

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

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

System..::.Object
  System..::.MarshalByRefObject
    System.ComponentModel..::.Component
      System.Windows.Forms..::.Control
        System.Windows.Forms..::.ScrollableControl
          System.Windows.Forms..::.ToolStrip
            System.Windows.Forms..::.BindingNavigator
この型のすべてのパブリック static (Visual Basic では Shared) メンバは、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

.NET Framework および .NET Compact Framework では、各プラットフォームのすべてのバージョンはサポートしていません。サポートされているバージョンについては、「.NET Framework システム要件」を参照してください。

.NET Framework

サポート対象 : 3.5、3.0、2.0
コミュニティ コンテンツ   コミュニティ コンテンツとは
新しいコンテンツの追加 RSS  注釈
Processing
Page view tracker