BindingsCollection Třída
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Představuje kolekci Binding objektů pro ovládací prvek.
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
- Dědičnost
- Odvozené
Příklady
Následující příklad vytvoří vazbu Text vlastnosti TextBox ovládacího prvku na pole v databázi.
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
Poznámky
Jednoduchá datová vazba je dosaženo přidáním Binding objektů do objektu BindingsCollection. K objektu Control , který dědí z třídy, má přístup BindingsCollection prostřednictvím DataBindings vlastnosti. Seznam ovládacích prvků Systému Windows, které podporují datovou vazbu, najdete v Binding této třídě.
Vlastnosti
| Name | Description |
|---|---|
| Count |
Získá celkový počet vazeb v kolekci. |
| 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 . |
| List |
Získá vazby v kolekci jako objekt. |
| 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á zadanou vazbu do kolekce. |
| AddCore(Binding) |
Binding Přidá do kolekce. |
| Clear() |
Vymaže kolekci vazeb objektů. |
| ClearCore() |
Vymaže kolekci všech členů. |
| 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. |
| OnCollectionChanging(CollectionChangeEventArgs) |
CollectionChanging Vyvolá událost. |
| Remove(Binding) |
Odstraní zadanou vazbu z kolekce. |
| RemoveAt(Int32) |
Odstraní vazbu z kolekce v zadaném indexu. |
| RemoveCore(Binding) |
Odebere zadanou Binding položku z kolekce. |
| ShouldSerializeMyAll() |
Získá hodnotu, která označuje, zda kolekce má být serializována. |
| 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. |
| CollectionChanging |
Nastane, když se kolekce chystá změnit. |
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. |