Manages the collection of ListManager objects for a Win Form.
Object
BindingManager
[Visual Basic] Public Class BindingManager Implements ICollection, IEnumerable [C#] public class BindingManager : ICollection, IEnumerable [C++] public __gc class BindingManager : public ICollection, IEnumerable [JScript] public class BindingManager implements ICollection, IEnumerable
Each Win Form has a BindingManager responsible for managing the collections that controls are bound to. It manages currency (or current position) and dependency.
The BindingManager maintains a current position for each collection. Simple databinding uses this current position to determine which object in the collection to data bind a control property to. As the current position is changed so does the object that a control property is bound to.
The BindingManager also maintains dependency relationships between collections. This allows the creation of Master/Details forms. For example, if a ComboBox control is the "master," and a DataGrid the "details" control, a dependency must be maintained between the two controls to keep the two synchronized--i.e. when the value of the ComboBox changes, so does the content of the DataGrid.
Use the BindingManager to return ListManager objects; for each data source used in a ListBinding, a single ListManager exists. Because of this unique relationship, the BindingManager does not have an Add method for adding ListManager objects. Instead, the BindingManager returns ListManager objects based on the data source.
See the Item property (BindingManager indexer) for more details on returning a ListManager.
See the ListBinding class for a list of possible data sources.
Namespace: System.WinForms
Assembly: System.WinForms.dll
The following example creates a ListBinding of a column in a DataTable to a TextBox control. The BindingManager is used to return the ListManager for the binding, which can then be used to advance the Position of the System.WinForms.Listmanager.
[Visual Basic]
' The next 4 lines go into the Declarations section of the form. Private myListManager As ListManager ' SuppliersProducts is a class derived from DataSet. Private ds As SuppliersProducts Private isBound As Boolean Private Sub InstantiateDataSet() ' The methods to populate the DataSet are not shown here. Set ds = New SuppliersProducts End Sub Private Sub BindTextBox() ' Test if the TextBox is already bound. If isBound Then Exit Sub ' Otherwise, bind the TextBox.Text property to the Suppliers.CompanyName column. TextBox1.Bindings.Add("Text", ds.Tables("Suppliers"), "CompanyName") isbound = True End Sub Private Sub GetListManager() ' Get the ListManager for the bound control using the BindingManager ' of the Win Form. To get the ListManager, pass the data source of the ' desired ListManager to the BindingManager. myListManager = Me.BindingManager(ds.Tables("Suppliers"), "") End Sub Private Sub MoveNext() ' To navigate the ListManager, increment the Position property. If myListManager.Position = myListManager.Count - 1 Then MessageBox.Show("End of records") Else myListManager.Position += 1 End If End Sub Private Sub MovePrevious() ' To navigate the ListManager, increment the Position property. If myListManager.Position = 0 Then MessageBox.Show("First record") Else myListManager.Position -= 1 End If End Sub Private Sub MoveFirst() ' Move to position 0 in the list. myListManager.Position = 0 End Sub Private Sub MoveLast() ' Move to the count -1 position. myListManager.Position = myListManager.Count - 1 End Sub
BindingManager Members | System.WinForms Namespace | ListManager | ListBinding | BindingsCollection