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 ovládací prvek DateTimePicker . K ControlBindingsCollection objektu DataBindings se přistupuje prostřednictvím 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 se provádí přidáním Binding objektů do objektu ControlBindingsCollection. Každý objekt, který dědí z Control třídy, má přístup k ControlBindingsCollection vlastnosti prostřednictvím DataBindings . Seznam ovládacích prvků Windows, které podporují datové vazby, najdete ve Binding třídě .

Obsahuje ControlBindingsCollection standardní metody kolekce, jako Addjsou , Cleara Remove.

Pokud chcete získat ovládací prvek, ke kterému ControlBindingsCollection patří, použijte Control vlastnost .

Konstruktory

ControlBindingsCollection(IBindableComponent)

Inicializuje novou instanci ControlBindingsCollection třídy se zadaným vázatelným ovládacím prvku.

Vlastnosti

BindableComponent

IBindableComponent Získá kolekci 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 pro objekt Binding v kolekci.

IsReadOnly

Získá hodnotu, která udává, zda je kolekce určena jen pro čtení.

(Zděděno od BaseCollection)
IsSynchronized

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

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

Získá hodnotu Binding v zadaném indexu.

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

Binding Získá zadaný názvem 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

Add(Binding)

Přidá zadaný Binding objekt do kolekce.

Add(String, Object, String)

Vytvoří pomocí Binding zadaného názvu vlastnosti ovládacího prvku, zdroje dat a datového člena a přidá ho 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 povoleno formátování, a přidá vazbu do kolekce.

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

Vytvoří vazbu, která sváže zadanou vlastnost ovládacího prvku na zadaný datový člen zadaného zdroje dat, volitelně povolí formátování, rozšíří hodnoty do zdroje dat na základě zadaného nastavení aktualizace a přidá vazbu do kolekce.

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

Vytvoří vazbu, která sváže zadanou vlastnost ovládacího prvku na zadaný datový člen zadaného zdroje dat, volitelně povolí formátování, rozšíří hodnoty do zdroje dat na základě zadaného nastavení aktualizace, nastaví vlastnost na zadanou hodnotu při DBNull vrácení ze zdroje dat a přidá vazbu do kolekce.

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

Vytvoří vazbu, která sváže zadanou vlastnost ovládacího prvku na zadaný datový člen zadaného zdroje dat, volitelně povolí formátování pomocí zadaného řetězce formátu, rozšíří hodnoty do zdroje dat na základě zadaného nastavení aktualizace, nastaví vlastnost na zadanou hodnotu při DBNull vrácení ze zdroje dat a přidá vazbu do kolekce.

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

Vytvoří vazbu, která sváže zadanou vlastnost ovládacího prvku na zadaný datový člen zadaného zdroje dat, volitelně povolí formátování pomocí zadaného řetězce formátu, rozšíří hodnoty do zdroje dat na základě zadaného nastavení aktualizace, nastaví vlastnost na zadanou hodnotu při DBNull vrácení ze zdroje dat, nastaví zadaného zprostředkovatele formátu. a přidání vazby do kolekce.

AddCore(Binding)

Přidá do kolekce vazbu.

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 používaného ke komunikaci se vzdáleným objektem.

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

Určí, zda se zadaný objekt rovná aktuálnímu objektu.

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

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

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

Slouží jako výchozí hashovací funkce.

(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á aktuální Type instanci.

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

Získá objekt služby životnosti, který řídí zásady životnosti pro tuto instanci.

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

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

(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í zadaný Binding objekt z kolekce.

RemoveAt(Int32)

Odstraní hodnotu Binding v zadaném indexu.

RemoveCore(Binding)

Odebere zadanou vazbu z kolekce.

ShouldSerializeMyAll()

Získá hodnotu, která označuje, zda má být kolekce 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

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í

Cast<TResult>(IEnumerable)

Přetypuje prvky objektu na IEnumerable zadaný typ.

OfType<TResult>(IEnumerable)

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

AsParallel(IEnumerable)

Umožňuje paralelizaci dotazu.

AsQueryable(IEnumerable)

Převede objekt na IEnumerableIQueryable.

Platí pro