This documentation is archived and is not being maintained.

BindableComponent.BindingContext Property

Visual Studio 2005

Gets or sets the BindingContext for the component.

Namespace: Microsoft.VisualStudio.Tools.Applications.Runtime
Assembly: Microsoft.VisualStudio.Tools.Applications.Runtime (in microsoft.visualstudio.tools.applications.runtime.dll)

public BindingContext BindingContext { get; set; }

The BindingContext object of a component is used to return a single BindingManagerBase object for all data-bound components contained by the component. The BindingManagerBase object keeps all components that are bound to the same data source synchronized. For example, setting the Position property of the BindingManagerBase specifies the item in the underlying list that all data-bound components point to.

The following code example demonstrates a handler for the Click event of a Button. When the Button is clicked, the example uses the BindingContext property to display the next data-bound item in a NamedRange. This code example is part of a larger code example provided for the BindableComponent class.

// Displays the next data item in the NamedRange.
void button1_Click(object sender, EventArgs e)
{
    if (namedRange1.BindingContext != null)
    {
        BindingManagerBase bindingManager1 =
            namedRange1.BindingContext[ds, "Customers"];

        // Display the next item.
        if (bindingManager1.Position < bindingManager1.Count - 1)
        {
            bindingManager1.Position++;
        }

        // Display the first item.
        else
        {
            bindingManager1.Position = 0;
        }
    }
}

Show: