BindingsCollection 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 una raccolta di Binding oggetti per un controllo .
public ref class BindingsCollection : System::Windows::Forms::BaseCollection
public class BindingsCollection : System.Windows.Forms.BaseCollection
type BindingsCollection = class
inherit BaseCollection
Public Class BindingsCollection
Inherits BaseCollection
- Ereditarietà
- Derivato
Esempio
Nell'esempio seguente viene associata la Text proprietà di un TextBox controllo a un campo di un database.
private:
void BindTextBoxControl()
{
DataSet^ myDataSet = gcnew DataSet;
/* Insert code to populate the DataSet with tables,
columns, and data. */
// Creates a new Binding object.
Binding^ myBinding = gcnew Binding(
"Text",myDataSet,"customers.custToOrders.OrderAmount" );
// Adds event delegates for the Parse and Format events.
myBinding->Parse += gcnew ConvertEventHandler( this, &Form1::CurrencyToDecimal );
myBinding->Format += gcnew ConvertEventHandler( this, &Form1::DecimalToCurrency );
// Adds the new Binding to the BindingsCollection.
text1->DataBindings->Add( myBinding );
}
void DecimalToCurrency( Object^ /*sender*/, ConvertEventArgs^ cevent )
{
/* This method is the Format event handler. Whenever the
control displays a new value, the value is converted from
its native Decimal type to a string. The ToString method
then formats the value as a Currency, by using the
formatting character "c". */
cevent->Value = safe_cast<Decimal ^>(cevent->Value)->ToString( "c" );
}
void CurrencyToDecimal( Object^ /*sender*/, ConvertEventArgs^ cevent )
{
/* This method is the Parse event handler. The Parse event
occurs whenever the displayed value changes. The static
Parse method of the Decimal structure converts the
string back to its native Decimal type. */
cevent->Value = Decimal::Parse( cevent->Value->ToString(),
NumberStyles::Currency, nullptr );
}
private void BindTextBoxControl()
{
DataSet myDataSet = new DataSet();
/* Insert code to populate the DataSet with tables,
columns, and data. */
// Creates a new Binding object.
Binding myBinding = new Binding
("Text", myDataSet, "customers.custToOrders.OrderAmount");
// Adds event delegates for the Parse and Format events.
myBinding.Parse += new ConvertEventHandler(CurrencyToDecimal);
myBinding.Format += new ConvertEventHandler(DecimalToCurrency);
// Adds the new Binding to the BindingsCollection.
text1.DataBindings.Add(myBinding);
}
private void DecimalToCurrency(object sender,
ConvertEventArgs cevent)
{
/* This method is the Format event handler. Whenever the
control displays a new value, the value is converted from
its native Decimal type to a string. The ToString method
then formats the value as a Currency, by using the
formatting character "c". */
cevent.Value = ((decimal) cevent.Value).ToString("c");
}
private void CurrencyToDecimal(object sender,
ConvertEventArgs cevent)
{
/* This method is the Parse event handler. The Parse event
occurs whenever the displayed value changes. The static
Parse method of the Decimal structure converts the
string back to its native Decimal type. */
cevent.Value = Decimal.Parse(cevent.Value.ToString(),
NumberStyles.Currency, null);
}
Private Sub BindTextBoxControl()
Dim myDataSet As New DataSet()
' Insert code to populate the DataSet with tables, columns, and data.
' Creates a new Binding object.
Dim myBinding As New Binding("Text", myDataSet, _
"customers.custToOrders.OrderAmount")
' Adds event delegates for the Parse and Format events.
AddHandler myBinding.Parse, AddressOf CurrencyToDecimal
AddHandler myBinding.Format, AddressOf DecimalToCurrency
' Adds the new Binding to the BindingsCollection.
text1.DataBindings.Add(myBinding)
End Sub
Private Sub DecimalToCurrency(sender As Object, _
cevent As ConvertEventArgs)
' This method is the Format event handler. Whenever the
' control displays a new value, the value is converted from
' its native Decimal type to a string. The ToString method
' then formats the value as a Currency, by using the
' formatting character "c".
cevent.Value = CDec(cevent.Value).ToString("c")
End Sub
Private Sub CurrencyToDecimal(sender As Object, _
cevent As ConvertEventArgs)
' This method is the Parse event handler. The Parse event
' occurs whenever the displayed value changes. The static
' Parse method of the Decimal structure converts the
' string back to its native Decimal type.
cevent.Value = Decimal.Parse(cevent.Value.ToString(), _
NumberStyles.Currency, nothing)
End Sub
Commenti
Il data binding semplice viene eseguito aggiungendo Binding oggetti a un oggetto BindingsCollection. Qualsiasi oggetto che eredita dalla Control classe può accedere a BindingsCollection tramite la DataBindings proprietà . Per un elenco dei controlli Windows che supportano il data binding, vedi la Binding classe .
Proprietà
| Nome | Descrizione |
|---|---|
| Count |
Ottiene il numero totale di associazioni nella raccolta. |
| 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. |
| List |
Ottiene le associazioni nella raccolta come oggetto . |
| 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'associazione specificata alla raccolta. |
| AddCore(Binding) |
Aggiunge un oggetto Binding all'insieme. |
| Clear() |
Cancella l'insieme di oggetti di associazione. |
| ClearCore() |
Cancella l'insieme di tutti i membri. |
| 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. |
| OnCollectionChanging(CollectionChangeEventArgs) |
Genera l'evento CollectionChanging. |
| Remove(Binding) |
Elimina l'associazione specificata dalla raccolta. |
| RemoveAt(Int32) |
Elimina l'associazione dalla raccolta in corrispondenza dell'indice specificato. |
| RemoveCore(Binding) |
Rimuove l'oggetto specificato Binding dalla raccolta. |
| ShouldSerializeMyAll() |
Ottiene un valore che indica se la raccolta deve essere serializzata. |
| ToString() |
Restituisce una stringa che rappresenta l'oggetto corrente. (Ereditato da Object) |
Eventi
| Nome | Descrizione |
|---|---|
| CollectionChanged |
Si verifica quando la raccolta è stata modificata. |
| CollectionChanging |
Si verifica quando la raccolta sta per cambiare. |
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. |