ControlBindingsCollection Classe
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Représente la collection de liaisons de données pour un contrôle.
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
- Héritage
- Attributs
Exemples
L’exemple de code suivant ajoute des Binding objets à cinq ControlBindingsCollection contrôles : quatre TextBox contrôles et un DateTimePicker contrôle. L’accès ControlBindingsCollection est accessible via la DataBindings propriété de la 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
Remarques
Une liaison de données simple est effectuée en ajoutant des Binding objets à un ControlBindingsCollection. Tout objet qui hérite de la Control classe peut accéder à la ControlBindingsCollection propriété via la DataBindings propriété. Pour obtenir la liste des contrôles Windows qui prennent en charge la liaison de données, consultez la Binding classe.
Contient ControlBindingsCollection des méthodes de collection standard telles que Add, Clearet Remove.
Pour obtenir le contrôle auquel appartient le ControlBindingsCollection membre, utilisez la Control propriété.
Constructeurs
| Nom | Description |
|---|---|
| ControlBindingsCollection(IBindableComponent) |
Initialise une nouvelle instance de la ControlBindingsCollection classe avec le contrôle pouvant être lié spécifié. |
Propriétés
| Nom | Description |
|---|---|
| BindableComponent |
Obtient la IBindableComponent collection de liaisons à laquelle appartient la collection. |
| Control |
Obtient le contrôle auquel appartient la collection. |
| Count |
Obtient le nombre total de liaisons dans la collection. (Hérité de BindingsCollection) |
| DefaultDataSourceUpdateMode |
Obtient ou définit la valeur par défaut DataSourceUpdateMode d’une Binding collection. |
| IsReadOnly |
Obtient une valeur indiquant si la collection est en lecture seule. (Hérité de BaseCollection) |
| IsSynchronized |
Obtient une valeur indiquant si l’accès au fichier ICollection est synchronisé. (Hérité de BaseCollection) |
| Item[Int32] |
Obtient l’index Binding spécifié. (Hérité de BindingsCollection) |
| Item[String] |
Obtient le Binding nom de propriété spécifié par le nom de propriété du contrôle. |
| List |
Obtient les liaisons de la collection en tant qu’objet. (Hérité de BindingsCollection) |
| SyncRoot |
Obtient un objet qui peut être utilisé pour synchroniser l’accès BaseCollectionau . (Hérité de BaseCollection) |
Méthodes
| Nom | Description |
|---|---|
| Add(Binding) |
Ajoute le paramètre spécifié Binding à la collection. |
| Add(String, Object, String, Boolean, DataSourceUpdateMode, Object, String, IFormatProvider) |
Crée une liaison qui lie la propriété de contrôle spécifiée au membre de données spécifié de la source de données spécifiée, en activant éventuellement la mise en forme avec la chaîne de format spécifiée, en propageant les valeurs vers la source de données en fonction du paramètre de mise à jour spécifié, en définissant la propriété sur la valeur spécifiée lorsqu’elle DBNull est retournée à partir de la source de données, en définissant le fournisseur de format spécifié, et ajout de la liaison à la collection. |
| Add(String, Object, String, Boolean, DataSourceUpdateMode, Object, String) |
Crée une liaison qui lie la propriété de contrôle spécifiée au membre de données spécifié de la source de données spécifiée, en activant éventuellement la mise en forme avec la chaîne de format spécifiée, en propageant les valeurs vers la source de données en fonction du paramètre de mise à jour spécifié, en définissant la propriété sur la valeur spécifiée lorsqu’elle DBNull est retournée à partir de la source de données et en ajoutant la liaison à la collection. |
| Add(String, Object, String, Boolean, DataSourceUpdateMode, Object) |
Crée une liaison qui lie la propriété de contrôle spécifiée au membre de données spécifié de la source de données spécifiée, en activant éventuellement la mise en forme, en propageant des valeurs vers la source de données en fonction du paramètre de mise à jour spécifié, en définissant la propriété sur la valeur spécifiée lorsqu’elle DBNull est retournée à partir de la source de données et en ajoutant la liaison à la collection. |
| Add(String, Object, String, Boolean, DataSourceUpdateMode) |
Crée une liaison qui lie la propriété de contrôle spécifiée au membre de données spécifié de la source de données spécifiée, en activant éventuellement la mise en forme, en propageant des valeurs vers la source de données en fonction du paramètre de mise à jour spécifié et en ajoutant la liaison à la collection. |
| Add(String, Object, String, Boolean) |
Crée une liaison avec le nom de propriété de contrôle, la source de données, le membre de données et les informations sur l’activation de la mise en forme et l’ajout de la liaison à la collection. |
| Add(String, Object, String) |
Crée un Binding nom de propriété de contrôle, une source de données et un membre de données spécifiés, puis l’ajoute à la collection. |
| AddCore(Binding) |
Ajoute une liaison à la collection. |
| Clear() |
Efface la collection des liaisons. |
| ClearCore() |
Efface les liaisons dans la collection. |
| CopyTo(Array, Int32) |
Copie tous les éléments de l’élément unidimensionnel Array actuel vers l’index de destination spécifié Array à partir de l’index de destination Array spécifié. (Hérité de BaseCollection) |
| CreateObjRef(Type) |
Crée un objet qui contient toutes les informations pertinentes requises pour générer un proxy utilisé pour communiquer avec un objet distant. (Hérité de MarshalByRefObject) |
| Equals(Object) |
Détermine si l’objet spécifié est égal à l’objet actuel. (Hérité de Object) |
| GetEnumerator() |
Obtient l’objet qui active l’itération via les membres de la collection. (Hérité de BaseCollection) |
| GetHashCode() |
Sert de fonction de hachage par défaut. (Hérité de Object) |
| GetLifetimeService() |
Obsolète.
Récupère l’objet de service de durée de vie actuel qui contrôle la stratégie de durée de vie de cette instance. (Hérité de MarshalByRefObject) |
| GetType() |
Obtient la Type de l’instance actuelle. (Hérité de Object) |
| InitializeLifetimeService() |
Obsolète.
Obtient un objet de service de durée de vie pour contrôler la stratégie de durée de vie de cette instance. (Hérité de MarshalByRefObject) |
| MemberwiseClone() |
Crée une copie superficielle du Objectactuel. (Hérité de Object) |
| MemberwiseClone(Boolean) |
Crée une copie superficielle de l’objet actuel MarshalByRefObject . (Hérité de MarshalByRefObject) |
| OnCollectionChanged(CollectionChangeEventArgs) |
Déclenche l’événement CollectionChanged. (Hérité de BindingsCollection) |
| OnCollectionChanging(CollectionChangeEventArgs) |
Déclenche l’événement CollectionChanging. (Hérité de BindingsCollection) |
| Remove(Binding) |
Supprime le spécifié Binding de la collection. |
| RemoveAt(Int32) |
Supprime l’index Binding spécifié. |
| RemoveCore(Binding) |
Supprime la liaison spécifiée de la collection. |
| ShouldSerializeMyAll() |
Obtient une valeur qui indique si la collection doit être sérialisée. (Hérité de BindingsCollection) |
| ToString() |
Retourne une chaîne qui représente l’objet actuel. (Hérité de Object) |
Événements
| Nom | Description |
|---|---|
| CollectionChanged |
Se produit lorsque la collection a changé. (Hérité de BindingsCollection) |
| CollectionChanging |
Se produit lorsque la collection est sur le point de changer. (Hérité de BindingsCollection) |
Méthodes d’extension
| Nom | Description |
|---|---|
| AsParallel(IEnumerable) |
Active la parallélisation d’une requête. |
| AsQueryable(IEnumerable) |
Convertit un IEnumerable en IQueryable. |
| Cast<TResult>(IEnumerable) |
Convertit les éléments d’un IEnumerable en type spécifié. |
| OfType<TResult>(IEnumerable) |
Filtre les éléments d’une IEnumerable en fonction d’un type spécifié. |