Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Initialisiert eine neue Instanz der BindingContext-Klasse.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)
Syntax
'Declaration
Public Sub New
'Usage
Dim instance As New BindingContext
public BindingContext ()
public:
BindingContext ()
public BindingContext ()
public function BindingContext ()
Hinweise
Wenn für dieselbe Datenquelle mehrere BindingManagerBase-Instanzen vorhanden sein sollen, erstellen Sie einen neuen BindingContext und legen ihn auf die BindingContext-Eigenschaft eines Objekts fest, das von der Control-Klasse erbt. Wenn z. B. zwei BindingManagerBase-Objekte (von zwei verschiedenen BindingContext-Objekten) vorhanden sind, können Sie die Position-Eigenschaften jeder BindingManagerBase auf unterschiedliche Werte festlegen. Dies bewirkt, dass jeder Satz datengebundener Steuerelemente andere Werte von derselben Datenquelle anzeigt.
Beispiel
Im folgenden Codebeispiel werden zwei neue BindingContext-Objekte erstellt, und jedes Objekt wird der BindingContext-Eigenschaft eines GroupBox-Steuerelements zugewiesen. GroupBox1 enthält TextBox1, und GroupBox2 enthält TextBox2. Hierzu wird die AddRange-Methode der Control.ControlCollection-Klasse verwendet. Dann werden den beiden TextBox-Steuerelementen Binding-Objekte hinzugefügt, und jedes wird an dieselbe Datenquelle und denselben Datenmember gebunden. Das Beispiel enthält außerdem zwei Ereignishandler, die mithilfe des BindingContext der GroupBox-Steuerelemente die Position-Eigenschaft für verschiedene BindingManagerBase-Objekte festlegen.
Private Sub BindControls()
Dim bcG1 As New BindingContext()
Dim bcG2 As New BindingContext()
groupBox1.BindingContext = bcG1
groupBox2.BindingContext = bcG2
textBox1.DataBindings.Add("Text", ds, "Customers.CustName")
textBox2.DataBindings.Add("Text", ds, "Customers.CustName")
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
groupBox1.BindingContext(ds, "Customers").Position += 1
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
groupBox2.BindingContext(ds, "Customers").Position += 1
End Sub
private void BindControls()
{
BindingContext bcG1 = new BindingContext();
BindingContext bcG2 = new BindingContext();
groupBox1.BindingContext = bcG1;
groupBox2.BindingContext = bcG2;
textBox1.DataBindings.Add("Text", ds, "Customers.CustName");
textBox2.DataBindings.Add("Text", ds, "Customers.CustName");
}
private void Button1_Click(object sender, EventArgs e)
{
groupBox1.BindingContext[ds, "Customers"].Position += 1;
}
private void Button2_Click(object sender, EventArgs e)
{
groupBox2.BindingContext[ds, "Customers"].Position += 1;
}
void BindControls()
{
System::Windows::Forms::BindingContext^ bcG1 = gcnew System::Windows::Forms::BindingContext;
System::Windows::Forms::BindingContext^ bcG2 = gcnew System::Windows::Forms::BindingContext;
groupBox1->BindingContext = bcG1;
groupBox2->BindingContext = bcG2;
textBox1->DataBindings->Add( "Text", ds, "Customers.CustName" );
textBox2->DataBindings->Add( "Text", ds, "Customers.CustName" );
}
void Button1_Click( Object^ /*sender*/, EventArgs^ /*e*/ )
{
groupBox1->BindingContext[ds, "Customers"]->Position = groupBox1->BindingContext[ds, "Customers"]->Position + 1;
}
void Button2_Click( Object^ /*sender*/, EventArgs^ /*e*/ )
{
groupBox2->BindingContext[ds, "Customers"]->Position = groupBox2->BindingContext[ds, "Customers"]->Position + 1;
}
private void BindControls()
{
BindingContext bcG1 = new BindingContext();
BindingContext bcG2 = new BindingContext();
groupBox1.set_BindingContext(bcG1);
groupBox2.set_BindingContext(bcG2);
textBox1.get_DataBindings().Add("Text", ds, "Customers.CustName");
textBox2.get_DataBindings().Add("Text", ds, "Customers.CustName");
} //BindControls
private void button1_Click(Object sender, EventArgs e)
{
groupBox1.get_BindingContext().get_Item(ds, "Customers").set_Position
(groupBox1.get_BindingContext().get_Item(ds, "Customers").
get_Position() + 1);
} //button1_Click
private void button2_Click(Object sender, EventArgs e)
{
groupBox2.get_BindingContext().get_Item(ds, "Customers").set_Position
(groupBox2.get_BindingContext().get_Item(ds, "Customers").
get_Position() + 1);
} //button2_Click
private function BindControls()
{
var bcG1 : System.Windows.Forms.BindingContext = new System.Windows.Forms.BindingContext;
var bcG2 : System.Windows.Forms.BindingContext = new System.Windows.Forms.BindingContext;
button1.BindingContext = bcG1;
button2.BindingContext = bcG2;
textBox1.DataBindings.Add(new Binding
("Text", ds, "customers.custName"));
textBox2.DataBindings.Add(new Binding
("Text", ds, "customers.custName"));
// Get the BindingManagerBase for the Customers table.
bmCustomers = this.BindingContext [ds, "Customers"];
}
private function Button1_Click(sender, e : EventArgs)
{
bmCustomers.Position += 1;
}
private function Button2_Click(sender, e : EventArgs)
{
bmCustomers.Position -= 1;
}
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
.NET Compact Framework
Unterstützt in: 2.0, 1.0
Siehe auch
Referenz
BindingContext-Klasse
BindingContext-Member
System.Windows.Forms-Namespace
BindingManagerBase