BindingsCollection Klasa

Definicja

Reprezentuje kolekcję Binding obiektów dla kontrolki.

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
Dziedziczenie
Pochodne

Przykłady

Poniższy przykład wiąże Text właściwość kontrolki TextBox z polem w bazie danych.

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

Uwagi

Proste powiązanie danych odbywa się przez dodanie Binding obiektów do obiektu BindingsCollection. Każdy obiekt dziedziczony z Control klasy może uzyskać dostęp do BindingsCollection obiektu za pośrednictwem DataBindings właściwości. Aby uzyskać listę kontrolek systemu Windows, które obsługują powiązanie danych, zobacz klasę Binding .

Właściwości

Count

Pobiera łączną liczbę powiązań w kolekcji.

IsReadOnly

Pobiera wartość wskazującą, czy kolekcja jest przeznaczona tylko do odczytu.

(Odziedziczone po BaseCollection)
IsSynchronized

Pobiera wartość wskazującą, czy dostęp do elementu ICollection jest synchronizowany.

(Odziedziczone po BaseCollection)
Item[Int32]

Pobiera element Binding w określonym indeksie.

List

Pobiera powiązania w kolekcji jako obiekt.

SyncRoot

Pobiera obiekt, który może służyć do synchronizowania dostępu do obiektu BaseCollection.

(Odziedziczone po BaseCollection)

Metody

Add(Binding)

Dodaje określone powiązanie do kolekcji.

AddCore(Binding)

Dodaje element Binding do kolekcji.

Clear()

Czyści kolekcję obiektów powiązań.

ClearCore()

Czyści kolekcję wszystkich elementów członkowskich.

CopyTo(Array, Int32)

Kopiuje wszystkie elementy bieżącego jednowymiarowego do określonego jednowymiarowego ArrayArray indeksu rozpoczynającego się od określonego indeksu docelowego Array .

(Odziedziczone po BaseCollection)
CreateObjRef(Type)

Tworzy obiekt zawierający wszystkie istotne informacje wymagane do wygenerowania serwera proxy używanego do komunikowania się z obiektem zdalnym.

(Odziedziczone po MarshalByRefObject)
Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetEnumerator()

Pobiera obiekt, który umożliwia iterowanie za pośrednictwem elementów członkowskich kolekcji.

(Odziedziczone po BaseCollection)
GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetLifetimeService()
Przestarzałe.

Pobiera bieżący obiekt usługi okresu istnienia, który kontroluje zasady okresu istnienia dla tego wystąpienia.

(Odziedziczone po MarshalByRefObject)
GetType()

Type Pobiera bieżące wystąpienie.

(Odziedziczone po Object)
InitializeLifetimeService()
Przestarzałe.

Uzyskuje obiekt usługi okresu istnienia, aby kontrolować zasady okresu istnienia dla tego wystąpienia.

(Odziedziczone po MarshalByRefObject)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
MemberwiseClone(Boolean)

Tworzy płytkią kopię bieżącego MarshalByRefObject obiektu.

(Odziedziczone po MarshalByRefObject)
OnCollectionChanged(CollectionChangeEventArgs)

CollectionChanged Zgłasza zdarzenie.

OnCollectionChanging(CollectionChangeEventArgs)

CollectionChanging Zgłasza zdarzenie.

Remove(Binding)

Usuwa określone powiązanie z kolekcji.

RemoveAt(Int32)

Usuwa powiązanie z kolekcji w określonym indeksie.

RemoveCore(Binding)

Usuwa określony Binding element z kolekcji.

ShouldSerializeMyAll()

Pobiera wartość wskazującą, czy kolekcja powinna być serializowana.

ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Zdarzenia

CollectionChanged

Występuje, gdy kolekcja uległa zmianie.

CollectionChanging

Występuje, gdy kolekcja ma ulec zmianie.

Metody rozszerzania

Cast<TResult>(IEnumerable)

Rzutuje elementy elementu IEnumerable do określonego typu.

OfType<TResult>(IEnumerable)

Filtruje elementy elementu IEnumerable na podstawie określonego typu.

AsParallel(IEnumerable)

Umożliwia równoległość zapytania.

AsQueryable(IEnumerable)

Konwertuje element IEnumerable na .IQueryable

Dotyczy

Zobacz też