ControlBindingsCollection Classe
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Rappresenta la raccolta di data binding per un controllo .
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
- Ereditarietà
- Attributi
Esempio
Nell'esempio di codice seguente vengono aggiunti Binding oggetti a un ControlBindingsCollection controllo di cinque controlli: quattro TextBox controlli e un DateTimePicker controllo . L'oggetto ControlBindingsCollection è accessibile tramite la DataBindings proprietà della 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
Commenti
Il data binding semplice viene eseguito aggiungendo Binding oggetti a un oggetto ControlBindingsCollection. Qualsiasi oggetto che eredita dalla Control classe può accedere a ControlBindingsCollection tramite la DataBindings proprietà . Per un elenco dei controlli Windows che supportano il data binding, vedi la Binding classe .
ControlBindingsCollection Contiene metodi di raccolta standard, ad Addesempio , Cleare Remove.
Per ottenere il controllo a cui appartiene, ControlBindingsCollection utilizzare la Control proprietà .
Costruttori
| Nome | Descrizione |
|---|---|
| ControlBindingsCollection(IBindableComponent) |
Inizializza una nuova istanza della ControlBindingsCollection classe con il controllo associabile specificato. |
Proprietà
| Nome | Descrizione |
|---|---|
| BindableComponent |
Ottiene l'insieme IBindableComponent di associazioni a cui appartiene. |
| Control |
Ottiene il controllo a cui appartiene la raccolta. |
| Count |
Ottiene il numero totale di associazioni nella raccolta. (Ereditato da BindingsCollection) |
| DefaultDataSourceUpdateMode |
Ottiene o imposta il valore predefinito DataSourceUpdateMode per un Binding oggetto nell'insieme. |
| IsReadOnly |
Ottiene un valore che indica se l'insieme è di sola lettura. (Ereditato da BaseCollection) |
| IsSynchronized |
Ottiene un valore che indica se l'accesso ICollection a è sincronizzato. (Ereditato da BaseCollection) |
| Item[Int32] |
Ottiene l'oggetto Binding in corrispondenza dell'indice specificato. (Ereditato da BindingsCollection) |
| Item[String] |
Ottiene l'oggetto Binding specificato dal nome della proprietà del controllo. |
| List |
Ottiene le associazioni nella raccolta come oggetto . (Ereditato da BindingsCollection) |
| SyncRoot |
Ottiene un oggetto che può essere utilizzato per sincronizzare l'accesso all'oggetto BaseCollection. (Ereditato da BaseCollection) |
Metodi
| Nome | Descrizione |
|---|---|
| Add(Binding) |
Aggiunge l'oggetto specificato Binding all'insieme. |
| Add(String, Object, String, Boolean, DataSourceUpdateMode, Object, String, IFormatProvider) |
Crea un'associazione che associa la proprietà del controllo specificata al membro dati specificato dell'origine dati specificata, abilitando facoltativamente la formattazione con la stringa di formato specificata, propagando i valori all'origine dati in base all'impostazione di aggiornamento specificata, impostando la proprietà sul valore specificato quando DBNull viene restituito dall'origine dati, impostando il provider di formato specificato, e aggiungendo l'associazione alla raccolta. |
| Add(String, Object, String, Boolean, DataSourceUpdateMode, Object, String) |
Crea un'associazione che associa la proprietà del controllo specificata al membro dati specificato dell'origine dati specificata, abilitando facoltativamente la formattazione con la stringa di formato specificata, propagando i valori all'origine dati in base all'impostazione di aggiornamento specificata, impostando la proprietà sul valore specificato quando DBNull viene restituito dall'origine dati e aggiungendo l'associazione alla raccolta. |
| Add(String, Object, String, Boolean, DataSourceUpdateMode, Object) |
Crea un'associazione che associa la proprietà del controllo specificata al membro dati specificato dell'origine dati specificata, abilitando facoltativamente la formattazione, propagando i valori all'origine dati in base all'impostazione di aggiornamento specificata, impostando la proprietà sul valore specificato quando DBNull viene restituito dall'origine dati e aggiungendo l'associazione alla raccolta. |
| Add(String, Object, String, Boolean, DataSourceUpdateMode) |
Crea un'associazione che associa la proprietà del controllo specificata al membro dati specificato dell'origine dati specificata, abilitando facoltativamente la formattazione, propagando i valori all'origine dati in base all'impostazione di aggiornamento specificata e aggiungendo l'associazione alla raccolta. |
| Add(String, Object, String, Boolean) |
Crea un'associazione con il nome della proprietà del controllo, l'origine dati, il membro dati e le informazioni sull'abilitazione della formattazione e aggiunge l'associazione alla raccolta. |
| Add(String, Object, String) |
Crea un Binding oggetto utilizzando il nome della proprietà del controllo, l'origine dati e il membro dati specificati e lo aggiunge alla raccolta. |
| AddCore(Binding) |
Aggiunge un'associazione alla raccolta. |
| Clear() |
Cancella la raccolta di associazioni. |
| ClearCore() |
Cancella le associazioni nella raccolta. |
| CopyTo(Array, Int32) |
Copia tutti gli elementi dell'oggetto unidimensionale corrente nell'oggetto unidimensionale ArrayArray specificato a partire dall'indice di destinazione Array specificato. (Ereditato da BaseCollection) |
| CreateObjRef(Type) |
Crea un oggetto che contiene tutte le informazioni pertinenti necessarie per generare un proxy utilizzato per comunicare con un oggetto remoto. (Ereditato da MarshalByRefObject) |
| Equals(Object) |
Determina se l'oggetto specificato è uguale all'oggetto corrente. (Ereditato da Object) |
| GetEnumerator() |
Ottiene l'oggetto che consente di scorrere i membri dell'insieme. (Ereditato da BaseCollection) |
| GetHashCode() |
Funge da funzione hash predefinita. (Ereditato da Object) |
| GetLifetimeService() |
Obsoleti.
Recupera l'oggetto servizio di durata corrente che controlla i criteri di durata per questa istanza. (Ereditato da MarshalByRefObject) |
| GetType() |
Ottiene il Type dell'istanza corrente. (Ereditato da Object) |
| InitializeLifetimeService() |
Obsoleti.
Ottiene un oggetto servizio di durata per controllare i criteri di durata per questa istanza. (Ereditato da MarshalByRefObject) |
| MemberwiseClone() |
Crea una copia superficiale del Objectcorrente. (Ereditato da Object) |
| MemberwiseClone(Boolean) |
Crea una copia superficiale dell'oggetto corrente MarshalByRefObject . (Ereditato da MarshalByRefObject) |
| OnCollectionChanged(CollectionChangeEventArgs) |
Genera l'evento CollectionChanged. (Ereditato da BindingsCollection) |
| OnCollectionChanging(CollectionChangeEventArgs) |
Genera l'evento CollectionChanging. (Ereditato da BindingsCollection) |
| Remove(Binding) |
Elimina l'oggetto specificato Binding dalla raccolta. |
| RemoveAt(Int32) |
Elimina l'oggetto Binding in corrispondenza dell'indice specificato. |
| RemoveCore(Binding) |
Rimuove l'associazione specificata dalla raccolta. |
| ShouldSerializeMyAll() |
Ottiene un valore che indica se la raccolta deve essere serializzata. (Ereditato da BindingsCollection) |
| ToString() |
Restituisce una stringa che rappresenta l'oggetto corrente. (Ereditato da Object) |
Eventi
| Nome | Descrizione |
|---|---|
| CollectionChanged |
Si verifica quando la raccolta è stata modificata. (Ereditato da BindingsCollection) |
| CollectionChanging |
Si verifica quando la raccolta sta per cambiare. (Ereditato da BindingsCollection) |
Metodi di estensione
| Nome | Descrizione |
|---|---|
| AsParallel(IEnumerable) |
Abilita la parallelizzazione di una query. |
| AsQueryable(IEnumerable) |
Converte un IEnumerable in un IQueryable. |
| Cast<TResult>(IEnumerable) |
Esegue il cast degli elementi di un IEnumerable al tipo specificato. |
| OfType<TResult>(IEnumerable) |
Filtra gli elementi di un IEnumerable in base a un tipo specificato. |