Aktualisiert: November 2007
Stellt die Benutzeroberfläche zur Navigation und Bearbeitung von Steuerelementen auf einem Formular dar, die an Daten gebunden sind.
Namespace:
System.Windows.Forms
Assembly:
System.Windows.Forms (in System.Windows.Forms.dll)
Visual Basic (Deklaration)
<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
Public Class BindingNavigator _
Inherits ToolStrip _
Implements ISupportInitialize
Visual Basic (Verwendung)
Dim instance As BindingNavigator
[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
public class BindingNavigator : ToolStrip,
ISupportInitialize
[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)]
public ref class BindingNavigator : public ToolStrip,
ISupportInitialize
/** @attribute ComVisibleAttribute(true) */
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */
public class BindingNavigator extends ToolStrip implements ISupportInitialize
public class BindingNavigator extends ToolStrip implements ISupportInitialize
Das BindingNavigator-Steuerelement stellt eine standardisierte Möglichkeit dar, zu Daten auf einem Formular zu navigieren und diese zu bearbeiten. In den meisten Fällen ist ein BindingNavigator mit einem BindingSource-Steuerelement kombiniert, um Daten auf einem Formular durchlaufen und mit diesen interagieren zu können. In diesen Fällen wird die BindingSource-Eigenschaft auf die zugeordnete System.Windows.Forms..::.BindingSource-Komponente festgelegt, die die Funktion einer Datenquelle übernimmt.
Die Standardbenutzeroberfläche des BindingNavigator-Steuerelements besteht aus einer Reihe von ToolStrip-Schaltflächen, Textfeldern und statischen Textelementen für die am häufigsten verwendeten datenbezogenen Aktionen, beispielsweise das Hinzufügen von Daten, das Löschen von Daten oder das Navigieren durch die Daten. Jedes dieser Steuerelemente kann über einen zugeordneten Member des BindingNavigator-Steuerelements abgerufen oder festgelegt werden. Analog gibt es eine 1:1-Entsprechung zu Membern innerhalb der BindingSource-Klasse, die dieselbe Funktion programmgesteuert ausführen, wie in der folgenden Tabelle gezeigt wird.
Wenn einem Formular ein BindingNavigator-Steuerelement hinzugefügt wird, und dieses an die Datenquelle gebunden wird, z. B. BindingSource, werden in dieser Tabelle die Beziehungen automatisch hergestellt.
Diese Symbolleiste können Sie mit einer der folgenden Methoden anpassen:
Erstellen Sie den BindingNavigator mit dem BindingNavigator(Boolean)-Konstruktor, der einen booleschen addStandardItems-Parameter akzeptiert, und legen Sie diesen Parameter auf false fest. Fügen Sie dann die gewünschten ToolStripItem-Objekte der Items-Auflistung hinzu.
Wenn Sie eine umfangreiche Anpassung wünschen oder Sie den benutzerdefinierten Entwurf wieder verwenden möchten, leiten Sie eine Klasse von BindingNavigator ab, und überschreiben Sie die AddStandardItems-Methode, um zusätzliche oder andere Standardelemente zu definieren.
Im folgenden Codebeispiel wird veranschaulicht, wie mit einem BindingNavigator-Steuerelement ein Dataset durchlaufen wird. Das Dataset ist einer DataView enthalten, die an ein TextBox-Steuerelement mit einer BindingSource-Komponente gebunden ist.
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
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
Alle öffentlichen static (Shared in Visual Basic)-Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.
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 und .NET Compact Framework unterstützen nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen für .NET Framework.
.NET Framework
Unterstützt in: 3.5, 3.0, 2.0
Referenz
Weitere Ressourcen