ControlBindingsCollection Classe

Definição

Representa a coleção de ligações de dados para um controlo.

public ref class ControlBindingsCollection : System::Windows::Forms::BindingsCollection
[System.ComponentModel.TypeConverter("System.Windows.Forms.Design.ControlBindingsConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public class ControlBindingsCollection : System.Windows.Forms.BindingsCollection
[System.ComponentModel.TypeConverter("System.Windows.Forms.Design.ControlBindingsConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public class ControlBindingsCollection : System.Windows.Forms.BindingsCollection
[System.ComponentModel.TypeConverter("System.Windows.Forms.Design.ControlBindingsConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public class ControlBindingsCollection : System.Windows.Forms.BindingsCollection
[<System.ComponentModel.TypeConverter("System.Windows.Forms.Design.ControlBindingsConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
type ControlBindingsCollection = class
    inherit BindingsCollection
[<System.ComponentModel.TypeConverter("System.Windows.Forms.Design.ControlBindingsConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
type ControlBindingsCollection = class
    inherit BindingsCollection
[<System.ComponentModel.TypeConverter("System.Windows.Forms.Design.ControlBindingsConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
type ControlBindingsCollection = class
    inherit BindingsCollection
Public Class ControlBindingsCollection
Inherits BindingsCollection
Herança
Atributos

Exemplos

O seguinte exemplo de código adiciona Binding objetos a um ControlBindingsCollection de cinco controlos: quatro TextBox controlos e um DateTimePicker controlo. O ControlBindingsCollection é acedido através da DataBindings propriedade da Control classe.

protected:
   void BindControls()
   {
      /* Create two Binding objects for the first two TextBox 
         controls. The data-bound property for both controls 
         is the Text property. The data source is a DataSet 
         (ds). The data member is the navigation path: 
         TableName.ColumnName. */
      textBox1->DataBindings->Add( gcnew Binding(
         "Text",ds,"customers.custName" ) );
      textBox2->DataBindings->Add( gcnew Binding(
         "Text",ds,"customers.custID" ) );
      
      /* Bind the DateTimePicker control by adding a new Binding. 
         The data member of the DateTimePicker is a navigation path:
         TableName.RelationName.ColumnName. */
      DateTimePicker1->DataBindings->Add( gcnew Binding(
         "Value",ds,"customers.CustToOrders.OrderDate" ) );
      
      /* Create a new Binding using the DataSet and a 
         navigation path(TableName.RelationName.ColumnName).
         Add event delegates for the Parse and Format events to 
         the Binding object, and add the object to the third 
         TextBox control's BindingsCollection. The delegates 
         must be added before adding the Binding to the 
         collection; otherwise, no formatting occurs until 
         the Current object of the BindingManagerBase for 
         the data source changes. */
      Binding^ b = gcnew Binding(
         "Text",ds,"customers.custToOrders.OrderAmount" );
      b->Parse += gcnew ConvertEventHandler(
         this, &Form1::CurrencyStringToDecimal );
      b->Format += gcnew ConvertEventHandler(
         this, &Form1::DecimalToCurrencyString );
      textBox3->DataBindings->Add( b );
      
      /*Bind the fourth TextBox to the Value of the 
         DateTimePicker control. This demonstates how one control
         can be data-bound to another.*/
      textBox4->DataBindings->Add( "Text", DateTimePicker1, "Value" );
      
      // Get the BindingManagerBase for the textBox4 Binding.
      BindingManagerBase^ bmText = this->BindingContext[
         DateTimePicker1 ];
      
      /* Print the Type of the BindingManagerBase, which is 
         a PropertyManager because the data source
         returns only a single property value. */
      Console::WriteLine( bmText->GetType() );
      
      // Print the count of managed objects, which is one.
      Console::WriteLine( bmText->Count );
      
      // Get the BindingManagerBase for the Customers table. 
      bmCustomers = this->BindingContext[ds, "Customers"];
      
      /* Print the Type and count of the BindingManagerBase.
         Because the data source inherits from IBindingList,
         it is a RelatedCurrencyManager (a derived class of
         CurrencyManager). */
      Console::WriteLine( bmCustomers->GetType() );
      Console::WriteLine( bmCustomers->Count );
      
      /* Get the BindingManagerBase for the Orders of the current
         customer using a navigation path: TableName.RelationName. */
      bmOrders = this->BindingContext[ds, "customers.CustToOrders"];
   }
protected void BindControls()
{
   /* Create two Binding objects for the first two TextBox 
   controls. The data-bound property for both controls 
   is the Text property. The data source is a DataSet 
   (ds). The data member is the navigation path: 
   TableName.ColumnName. */
   textBox1.DataBindings.Add(new Binding
   ("Text", ds, "customers.custName"));
   textBox2.DataBindings.Add(new Binding
   ("Text", ds, "customers.custID"));
      
   /* Bind the DateTimePicker control by adding a new Binding. 
   The data member of the DateTimePicker is a navigation path:
   TableName.RelationName.ColumnName. */
   DateTimePicker1.DataBindings.Add(new 
   Binding("Value", ds, "customers.CustToOrders.OrderDate"));

   /* Create a new Binding using the DataSet and a 
   navigation path(TableName.RelationName.ColumnName).
   Add event delegates for the Parse and Format events to 
   the Binding object, and add the object to the third 
   TextBox control's BindingsCollection. The delegates 
   must be added before adding the Binding to the 
   collection; otherwise, no formatting occurs until 
   the Current object of the BindingManagerBase for 
   the data source changes. */
   Binding b = new Binding
   ("Text", ds, "customers.custToOrders.OrderAmount");
   b.Parse+=new ConvertEventHandler(CurrencyStringToDecimal);
   b.Format+=new ConvertEventHandler(DecimalToCurrencyString);
   textBox3.DataBindings.Add(b);

   /*Bind the fourth TextBox to the Value of the 
   DateTimePicker control. This demonstates how one control
   can be data-bound to another.*/
   textBox4.DataBindings.Add("Text", DateTimePicker1,"Value");

   // Get the BindingManagerBase for the textBox4 Binding.
   BindingManagerBase bmText = this.BindingContext
   [DateTimePicker1];

   /* Print the Type of the BindingManagerBase, which is 
   a PropertyManager because the data source
   returns only a single property value. */
   Console.WriteLine(bmText.GetType().ToString());

   // Print the count of managed objects, which is one.
   Console.WriteLine(bmText.Count);

   // Get the BindingManagerBase for the Customers table. 
   bmCustomers = this.BindingContext [ds, "Customers"];

   /* Print the Type and count of the BindingManagerBase.
   Because the data source inherits from IBindingList,
   it is a RelatedCurrencyManager (a derived class of
   CurrencyManager). */
   Console.WriteLine(bmCustomers.GetType().ToString());
   Console.WriteLine(bmCustomers.Count);
   
   /* Get the BindingManagerBase for the Orders of the current
   customer using a navigation path: TableName.RelationName. */ 
   bmOrders = this.BindingContext[ds, "customers.CustToOrders"];
}
Protected Sub BindControls()
    ' Create two Binding objects for the first two TextBox 
    ' controls. The data-bound property for both controls 
    ' is the Text property. The data source is a DataSet 
    ' (ds). The data member is the navigation path: 
    ' TableName.ColumnName. 
    textBox1.DataBindings.Add _
       (New Binding("Text", ds, "customers.custName"))
    textBox2.DataBindings.Add _
       (New Binding("Text", ds, "customers.custID"))
    
    ' Bind the DateTimePicker control by adding a new Binding. 
    ' The data member of the DateTimePicker is a navigation path:
    ' TableName.RelationName.ColumnName. 
    DateTimePicker1.DataBindings.Add _
       (New Binding("Value", ds, "customers.CustToOrders.OrderDate"))
    
    ' Create a new Binding using the DataSet and a 
    ' navigation path(TableName.RelationName.ColumnName).
    ' Add event delegates for the Parse and Format events to 
    ' the Binding object, and add the object to the third 
    ' TextBox control's BindingsCollection. The delegates 
    ' must be added before adding the Binding to the 
    ' collection; otherwise, no formatting occurs until 
    ' the Current object of the BindingManagerBase for 
    ' the data source changes. 
    Dim b As New Binding("Text", ds, "customers.custToOrders.OrderAmount")
    AddHandler b.Parse, AddressOf CurrencyStringToDecimal
    AddHandler b.Format, AddressOf DecimalToCurrencyString
    textBox3.DataBindings.Add(b)
    
    ' Bind the fourth TextBox to the Value of the 
    ' DateTimePicker control. This demonstates how one control
    ' can be data-bound to another.
    textBox4.DataBindings.Add("Text", DateTimePicker1, "Value")
    
    ' Get the BindingManagerBase for the textBox4 Binding.
    Dim bmText As BindingManagerBase = Me.BindingContext(DateTimePicker1)
    
    ' Print the Type of the BindingManagerBase, which is 
    ' a PropertyManager because the data source
    ' returns only a single property value. 
    Console.WriteLine(bmText.GetType().ToString())
    
    ' Print the count of managed objects, which is one.
    Console.WriteLine(bmText.Count)
    
    ' Get the BindingManagerBase for the Customers table. 
    bmCustomers = Me.BindingContext(ds, "Customers")
    
    ' Print the Type and count of the BindingManagerBase.
    ' Because the data source inherits from IBindingList,
    ' it is a RelatedCurrencyManager (a derived class of
    ' CurrencyManager). 
    Console.WriteLine(bmCustomers.GetType().ToString())
    Console.WriteLine(bmCustomers.Count)
    
    ' Get the BindingManagerBase for the Orders of the current
    ' customer using a navigation path: TableName.RelationName. 
    bmOrders = Me.BindingContext(ds, "customers.CustToOrders")
End Sub

Observações

A ligação simples de dados é realizada adicionando Binding objetos a um ControlBindingsCollection. Qualquer objeto que herde da Control classe pode aceder à ControlBindingsCollection propriedade através DataBindings da propriedade. Para uma lista de controlos de Windows que suportam ligação de dados, veja a classe Binding.

Contém ControlBindingsCollection métodos de coleção padrão como Add, Clear, e Remove.

Para obter o controlo a que pertence, ControlBindingsCollection use a Control propriedade.

Construtores

Name Description
ControlBindingsCollection(IBindableComponent)

Inicializa uma nova instância da ControlBindingsCollection classe com o controlo vinculável especificado.

Propriedades

Name Description
BindableComponent

Obtém o IBindableComponent lugar a que pertence a coleção de encadernação.

Control

Fica com o controlo a que pertence a coleção.

Count

Obtém o número total de encadernações na coleção.

(Herdado de BindingsCollection)
DefaultDataSourceUpdateMode

Obtém ou define o padrão DataSourceUpdateMode de a Binding na coleção.

IsReadOnly

Recebe um valor que indica se a coleção é apenas de leitura.

(Herdado de BaseCollection)
IsSynchronized

Obtém um valor que indica se o acesso ao ICollection está sincronizado.

(Herdado de BaseCollection)
Item[Int32]

Obtém o Binding no índice especificado.

(Herdado de BindingsCollection)
Item[String]

Obtém o Binding especificado pelo nome da propriedade do controlo.

List

Recebe as encadernações da coleção como um objeto.

(Herdado de BindingsCollection)
SyncRoot

Obtém um objeto que pode ser usado para sincronizar o acesso ao BaseCollection.

(Herdado de BaseCollection)

Métodos

Name Description
Add(Binding)

Adiciona o especificado Binding à coleção.

Add(String, Object, String, Boolean, DataSourceUpdateMode, Object, String, IFormatProvider)

Cria uma ligação que associa a propriedade de controlo especificada ao membro de dados especificado da fonte de dados especificada, ativando opcionalmente a formatação com a string de formato especificada, propagando valores para a fonte de dados com base na definição de atualização especificada, definindo a propriedade para o valor especificado quando DBNull é devolvido da fonte de dados, definindo o fornecedor de formato especificado, e adicionar a encadernação à coleção.

Add(String, Object, String, Boolean, DataSourceUpdateMode, Object, String)

Cria uma ligação que associa a propriedade de controlo especificada ao membro de dados especificado da fonte de dados especificada, ativando opcionalmente a formatação com a cadeia de formato especificada, propagando valores para a fonte de dados com base na definição de atualização especificada, definindo a propriedade para o valor especificado quando DBNull é devolvida da fonte de dados e adicionando a ligação à coleção.

Add(String, Object, String, Boolean, DataSourceUpdateMode, Object)

Cria uma ligação que associa a propriedade de controlo especificada ao membro de dados especificado da fonte de dados especificada, permitindo opcionalmente formatação, propagação de valores para a fonte de dados com base na configuração de atualização especificada, definição da propriedade para o valor especificado quando DBNull retorna da fonte de dados e adição da ligação à coleção.

Add(String, Object, String, Boolean, DataSourceUpdateMode)

Cria uma ligação que vincula a propriedade de controlo especificada ao membro de dados especificado da fonte de dados especificada, ativando opcionalmente formatação, propagação de valores para a fonte de dados com base na configuração de atualização especificada e adicionando a ligação à coleção.

Add(String, Object, String, Boolean)

Cria uma ligação com o nome da propriedade de controlo especificada, fonte de dados, membro de dados e informações sobre se a formatação está ativada, e adiciona a ligação à coleção.

Add(String, Object, String)

Cria um Binding usando o nome da propriedade de controlo especificado, a fonte de dados e o membro de dados, e adiciona-o à coleção.

AddCore(Binding)

Adiciona uma encadernação à coleção.

Clear()

Limpa a coleção de quaisquer encadernações.

ClearCore()

Limpa as encadernações da coleção.

CopyTo(Array, Int32)

Copia todos os elementos do unidimensional Array atual para o unidimensional Array especificado, começando no índice de destino Array especificado.

(Herdado de BaseCollection)
CreateObjRef(Type)

Cria um objeto que contém toda a informação relevante necessária para gerar um proxy usado para comunicar com um objeto remoto.

(Herdado de MarshalByRefObject)
Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.

(Herdado de Object)
GetEnumerator()

Obtém o objeto que permite iterar através dos membros da coleção.

(Herdado de BaseCollection)
GetHashCode()

Serve como função de hash predefinida.

(Herdado de Object)
GetLifetimeService()

Recupera o objeto de serviço de tempo de vida atual que controla a política de vida útil neste caso.

(Herdado de MarshalByRefObject)
GetType()

Obtém o Type da instância atual.

(Herdado de Object)
InitializeLifetimeService()

Obtém-se um objeto de serviço vitalício para controlar a apólice vitalícia neste caso.

(Herdado de MarshalByRefObject)
MemberwiseClone()

Cria uma cópia superficial do atual Object.

(Herdado de Object)
MemberwiseClone(Boolean)

Cria uma cópia superficial do objeto atual MarshalByRefObject .

(Herdado de MarshalByRefObject)
OnCollectionChanged(CollectionChangeEventArgs)

Eleva o CollectionChanged evento.

(Herdado de BindingsCollection)
OnCollectionChanging(CollectionChangeEventArgs)

Eleva o CollectionChanging evento.

(Herdado de BindingsCollection)
Remove(Binding)

Elimina o especificado Binding da coleção.

RemoveAt(Int32)

Apaga o Binding no índice especificado.

RemoveCore(Binding)

Remove a encadernação especificada da coleção.

ShouldSerializeMyAll()

Recebe um valor que indica se a coleção deve ser serializada.

(Herdado de BindingsCollection)
ToString()

Devolve uma cadeia que representa o objeto atual.

(Herdado de Object)

evento

Name Description
CollectionChanged

Ocorre quando a coleção mudou.

(Herdado de BindingsCollection)
CollectionChanging

Ocorre quando a coleção está prestes a mudar.

(Herdado de BindingsCollection)

Métodos da Extensão

Name Description
AsParallel(IEnumerable)

Permite a paralelização de uma consulta.

AsQueryable(IEnumerable)

Converte um IEnumerable para um IQueryable.

Cast<TResult>(IEnumerable)

Conjura os elementos de an IEnumerable para o tipo especificado.

OfType<TResult>(IEnumerable)

Filtra os elementos de um IEnumerable com base num tipo especificado.

Aplica-se a