BindingContext BindingContext BindingContext Constructor

Definição

Inicializa uma nova instância da classe BindingContext.Initializes a new instance of the BindingContext class.

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

Exemplos

O exemplo de código a seguir cria BindingContext dois novos objetos e atribui cada objeto BindingContext à propriedade de um GroupBox controle.The following code example creates two new BindingContext objects and assigns each object to the BindingContext property of a GroupBox control. GroupBox1Contains TextBox1e GroupBox2 Contains AddRange (queControl.ControlCollection é realizado usando o método da classe). TextBox2GroupBox1 contains TextBox1, and GroupBox2 contains TextBox2 (which is accomplished by using the AddRange method of the Control.ControlCollection class). Em seguida, o Binding exemplo adiciona objetos aos TextBox dois controles, associando cada um deles à mesma fonte de dados e ao membro de dados.The example then adds Binding objects to the two TextBox controls, binding each to the same data source and data member. O exemplo também mostra dois manipuladores de eventos que usam BindingContext o GroupBox dos controles para definir a Position Propriedade em objetos BindingManagerBase diferentes.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

Comentários

Se você BindingManagerBase quiser ter várias instâncias para a mesma fonte de dados, crie uma nova BindingContext e defina-a como a BindingContext Control propriedade de um objeto herdado da classe.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 exemplo, se você tiver dois BindingManagerBase objetos (de dois objetos BindingContext diferentes), poderá definir as Position Propriedades de cada BindingManagerBase um com 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. Isso faz com que cada conjunto de controles vinculados a dados exiba valores diferentes da mesma fonte de dados.This causes each set of data-bound controls to display different values from the same data source.

Aplica-se a

Veja também