Export (0) Print
Expand All

BindingContext Constructor

Initializes a new instance of the BindingContext class.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

'Declaration
Public Sub New

If you want to have multiple BindingManagerBase instances for the same data source, create a new BindingContext and set it to the BindingContext property of an object that inherits from the Control class. For example, if you have two BindingManagerBase objects (from two different BindingContext objects), you can set the Position properties of each BindingManagerBase to different values. This causes each set of data-bound controls to display different values from the same data source.

The following code example creates two new BindingContext objects and assigns each object to the BindingContext property of a GroupBox control. GroupBox1 contains TextBox1, and GroupBox2 contains TextBox2 (which is accomplished by using the AddRange method of the Control.ControlCollection class). The example then adds Binding objects to the two TextBox controls, binding each to the same data source and data member. The example also shows two event handlers that use the BindingContext from the GroupBox controls to set the Position property on different BindingManagerBase objects.

 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

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.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