BindingContext BindingContext BindingContext Constructor

Definición

Inicializa una nueva instancia de la clase BindingContext.Initializes a new instance of the BindingContext class.

public:
 BindingContext();
public BindingContext ();
Public Sub New ()

Ejemplos

En el ejemplo de código siguiente se crea dos nuevas BindingContext objetos y asigna cada objeto a la BindingContext propiedad de un GroupBox control.The following code example creates two new BindingContext objects and assigns each object to the BindingContext property of a GroupBox control. GroupBox1 contiene TextBox1, y GroupBox2 contiene TextBox2 (que se logra mediante el AddRange método de la Control.ControlCollection clase).GroupBox1 contains TextBox1, and GroupBox2 contains TextBox2 (which is accomplished by using the AddRange method of the Control.ControlCollection class). En el ejemplo, a continuación, agrega Binding objetos a los dos TextBox controles, enlace cada uno para el mismo miembro de datos y el origen de datos.The example then adds Binding objects to the two TextBox controls, binding each to the same data source and data member. El ejemplo también muestra dos controladores de eventos que usan el BindingContext desde el GroupBox controles para establecer el Position propiedad en diferentes BindingManagerBase objetos.The example also shows two event handlers that use the BindingContext from the GroupBox controls to set the Position property on different BindingManagerBase objects.

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.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;
}
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

Comentarios

Si desea tener varios BindingManagerBase instancias del mismo origen de datos, cree un nuevo BindingContext y establézcalo como el BindingContext propiedad de un objeto que hereda de la Control clase.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. Por ejemplo, si tiene dos BindingManagerBase objetos (de dos diferentes BindingContext objetos), puede establecer el Position propiedades de cada BindingManagerBase en valores diferentes.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. Esto hace que cada conjunto de controles enlazados a datos para mostrar valores diferentes del mismo origen de datos.This causes each set of data-bound controls to display different values from the same data source.

Se aplica a

Consulte también: