Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

BindingContext::Item Property (Object, String)

Gets a BindingManagerBase that is associated with the specified data source and data member.

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

public:
property BindingManagerBase^ Item[Object^ dataSource, String^ dataMember] {
	BindingManagerBase^ get (Object^ dataSource, String^ dataMember);
}

Parameters

dataSource
Type: System::Object

The data source associated with a particular BindingManagerBase.

dataMember
Type: System::String

A navigation path containing the information that resolves to a specific BindingManagerBase.

Property Value

Type: System.Windows.Forms::BindingManagerBase
The BindingManagerBase for the specified data source and data member.

ExceptionCondition
Exception

The specified dataMember does not exist within the data source.

Use this overload when the BindingManagerBase manages a set of Binding objects for which the data source contains multiple objects. For example, a DataSet can contain several DataTable objects linked by DataRelation objects. In such a case, the navigation path is required to enable the BindingContext to return the correct BindingManagerBase.

NoteNote

The Item property will always return a BindingManagerBase, when the dataMember parameter is valid. It will never return nullptr.

See the Binding class for a list of possible data sources and for information about creating bindings between controls and data sources.

If the desired BindingManagerBase manages a list, the navigation path must also end with a list. For example, the following C# code binds a TextBox control to the order date in a table of orders. The navigation path includes the TableName, the RelationName, and the ColumnName. However, the BindingManagerBase must be retrieved using only the TableName and RelationName (which resolves to a list).

// The navigation path for a Binding ends with a property.
textBox1.DataBindings.Add
("Text", dataSet1, "Customers.custToOrders.OrderDate");
// The navigation path for the BindingManagerBase ends with a list.
BindingManagerBase bmOrders = this.BindingContext
[dataSet1, "Customers.custToOrders"];

When returning a BindingManagerBase, you should use the same data source as the Binding and modify only the navigation path.

Use the Contains method to determine if the desired BindingManagerBase already exists.

The following code example demonstrates how to use the Item to retrieve the BindingManagerBase for a particular binding. It also shows how to handle the BindingComplete event for the BindingManagerBase to ensure multiple controls bound to the same data source remain synchronized when one of the control values is changed. To run this example, paste the code into a Windows Form and call the InitializeControlsAndData method from the form's constructor or Load event-handling method.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft