Sdílet prostřednictvím


ControlBindingsCollection Třída

Definice

Představuje kolekci datových vazeb pro ovládací prvek.

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
Dědičnost
Atributy

Příklady

Následující příklad kódu přidá Binding objekty do ControlBindingsCollection pěti ovládacích prvků: čtyři TextBox ovládací prvky a DateTimePicker ovládací prvek. Tato ControlBindingsCollection vlastnost je přístupná prostřednictvím DataBindings vlastnosti Control třídy.

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

Poznámky

Jednoduchá datová vazba je dosaženo přidáním Binding objektů do objektu ControlBindingsCollection. K objektu Control , který dědí z třídy, má přístup ControlBindingsCollection prostřednictvím DataBindings vlastnosti. Seznam ovládacích prvků Systému Windows, které podporují datovou vazbu, najdete v Binding této třídě.

Obsahuje ControlBindingsCollection standardní metody shromažďování, například Add, Cleara Remove.

K získání ovládacího prvku, ke kterému ControlBindingsCollection patří, použijte Control vlastnost.

Konstruktory

Name Description
ControlBindingsCollection(IBindableComponent)

Inicializuje novou instanci ControlBindingsCollection třídy pomocí zadaného bindable ovládacího prvku.

Vlastnosti

Name Description
BindableComponent

Získá kolekci IBindableComponent vazeb, do které patří.

Control

Získá ovládací prvek, do kterého kolekce patří.

Count

Získá celkový počet vazeb v kolekci.

(Zděděno od BindingsCollection)
DefaultDataSourceUpdateMode

Získá nebo nastaví výchozí DataSourceUpdateMode hodnotu pro kolekci Binding .

IsReadOnly

Získá hodnotu určující, zda kolekce je jen pro čtení.

(Zděděno od BaseCollection)
IsSynchronized

Získá hodnotu označující, zda je přístup k sadě ICollection synchronizován.

(Zděděno od BaseCollection)
Item[Int32]

Získá na zadaném indexu Binding .

(Zděděno od BindingsCollection)
Item[String]

Binding Získá zadaný název vlastnosti ovládacího prvku.

List

Získá vazby v kolekci jako objekt.

(Zděděno od BindingsCollection)
SyncRoot

Získá objekt, který lze použít k synchronizaci přístupu k BaseCollection.

(Zděděno od BaseCollection)

Metody

Name Description
Add(Binding)

Přidá zadaný Binding objekt do kolekce.

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

Vytvoří vazbu, která vytvoří vazbu zadané vlastnosti ovládacího prvku na zadaný datový člen zadaného zdroje dat, volitelně povolení formátování pomocí zadaného řetězce formátu, šíření hodnot do zdroje dat na základě zadaného nastavení aktualizace, nastavení vlastnosti na zadanou hodnotu při DBNull vrácení ze zdroje dat, nastavení zadaného zprostředkovatele formátu, a přidání vazby do kolekce.

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

Vytvoří vazbu, která vytvoří vazbu zadané vlastnosti ovládacího prvku na zadaný datový člen zadaného zdroje dat, volitelně povolení formátování pomocí zadaného formátovacího řetězce, šíření hodnot do zdroje dat na základě zadaného nastavení aktualizace, nastavení vlastnosti na zadanou hodnotu při DBNull vrácení ze zdroje dat a přidání vazby do kolekce.

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

Vytvoří vazbu, která vytvoří vazbu zadané vlastnosti ovládacího prvku na zadaný datový člen zadaného zdroje dat, volitelně povolení formátování, šíření hodnot do zdroje dat na základě zadaného nastavení aktualizace, nastavení vlastnosti na zadanou hodnotu při DBNull vrácení ze zdroje dat a přidání vazby do kolekce.

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

Vytvoří vazbu, která vytvoří vazbu zadané vlastnosti ovládacího prvku na zadaný datový člen zadaného zdroje dat, volitelně povolení formátování, šíření hodnot do zdroje dat na základě zadaného nastavení aktualizace a přidání vazby do kolekce.

Add(String, Object, String, Boolean)

Vytvoří vazbu se zadaným názvem vlastnosti ovládacího prvku, zdrojem dat, datovým členem a informacemi o tom, zda je formátování povoleno, a přidá vazbu do kolekce.

Add(String, Object, String)

Binding Vytvoří pomocí zadaného názvu vlastnosti ovládacího prvku, zdroje dat a datového člena a přidá ho do kolekce.

AddCore(Binding)

Přidá vazbu do kolekce.

Clear()

Vymaže kolekci všech vazeb.

ClearCore()

Vymaže vazby v kolekci.

CopyTo(Array, Int32)

Zkopíruje všechny prvky aktuálního jednorozměrného Array do zadaného jednorozměrného Array indexu počínaje zadaným cílovým Array indexem.

(Zděděno od BaseCollection)
CreateObjRef(Type)

Vytvoří objekt, který obsahuje všechny relevantní informace potřebné k vygenerování proxy serveru sloužícího ke komunikaci se vzdáleným objektem.

(Zděděno od MarshalByRefObject)
Equals(Object)

Určuje, zda je zadaný objekt roven aktuálnímu objektu.

(Zděděno od Object)
GetEnumerator()

Získá objekt, který umožňuje iterace prostřednictvím členů kolekce.

(Zděděno od BaseCollection)
GetHashCode()

Slouží jako výchozí funkce hash.

(Zděděno od Object)
GetLifetimeService()
Zastaralé.

Načte objekt služby aktuální životnosti, který řídí zásady životnosti pro tuto instanci.

(Zděděno od MarshalByRefObject)
GetType()

Získá Type aktuální instance.

(Zděděno od Object)
InitializeLifetimeService()
Zastaralé.

Získá objekt služby životnosti pro řízení zásad životnosti pro tuto instanci.

(Zděděno od MarshalByRefObject)
MemberwiseClone()

Vytvoří mělkou kopii aktuálního Object.

(Zděděno od Object)
MemberwiseClone(Boolean)

Vytvoří mělkou kopii aktuálního MarshalByRefObject objektu.

(Zděděno od MarshalByRefObject)
OnCollectionChanged(CollectionChangeEventArgs)

CollectionChanged Vyvolá událost.

(Zděděno od BindingsCollection)
OnCollectionChanging(CollectionChangeEventArgs)

CollectionChanging Vyvolá událost.

(Zděděno od BindingsCollection)
Remove(Binding)

Odstraní zadanou Binding z kolekce.

RemoveAt(Int32)

Odstraní v zadaném indexu Binding .

RemoveCore(Binding)

Odebere zadanou vazbu z kolekce.

ShouldSerializeMyAll()

Získá hodnotu, která označuje, zda kolekce má být serializována.

(Zděděno od BindingsCollection)
ToString()

Vrátí řetězec, který představuje aktuální objekt.

(Zděděno od Object)

Událost

Name Description
CollectionChanged

Nastane, když se kolekce změnila.

(Zděděno od BindingsCollection)
CollectionChanging

Nastane, když se kolekce chystá změnit.

(Zděděno od BindingsCollection)

Metody rozšíření

Name Description
AsParallel(IEnumerable)

Umožňuje paralelizaci dotazu.

AsQueryable(IEnumerable)

Převede IEnumerable na IQueryable.

Cast<TResult>(IEnumerable)

Přetypuje prvky IEnumerable na zadaný typ.

OfType<TResult>(IEnumerable)

Filtruje prvky IEnumerable na základě zadaného typu.

Platí pro