BindingsCollection クラス
定義
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
- 継承
- 派生
例
次の例では、 Text コントロールのプロパティ TextBox をデータベースのフィールドにバインドします。The following example binds the Text property of a TextBox control to a field in a database.
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
注釈
単純なデータバインディングは、にオブジェクトを追加することで実現され Binding BindingsCollection ます。Simple data binding is accomplished by adding Binding objects to a BindingsCollection. クラスから継承されたオブジェクトは、 Control BindingsCollection プロパティを介してにアクセスでき DataBindings ます。Any object that inherits from the Control class can access the BindingsCollection through the DataBindings property. データバインディングをサポートする Windows コントロールの一覧については、クラスを参照してください Binding 。For a list of Windows controls that support data binding, see the Binding class.
プロパティ
Count |
コレクション内のバインディングの合計数を取得します。Gets the total number of bindings in the collection. |
IsReadOnly |
コレクションが読み取り専用かどうかを示す値を取得します。Gets a value indicating whether the collection is read-only. (継承元 BaseCollection) |
IsSynchronized |
ICollection へのアクセスの同期がとられているかどうかを示す値を取得します。Gets a value indicating whether access to the ICollection is synchronized. (継承元 BaseCollection) |
Item[Int32] |
指定されたインデックス位置にある Binding を取得します。Gets the Binding at the specified index. |
List |
コレクション内のバインディングをオブジェクトとして取得します。Gets the bindings in the collection as an object. |
SyncRoot |
BaseCollection へのアクセスを同期するために使用できるオブジェクトを取得します。Gets an object that can be used to synchronize access to the BaseCollection. (継承元 BaseCollection) |
メソッド
Add(Binding) |
指定したバインディングをコレクションに追加します。Adds the specified binding to the collection. |
AddCore(Binding) | |
Clear() |
バインディング オブジェクトのコレクションを削除します。Clears the collection of binding objects. |
ClearCore() |
メンバーのコレクションを消去します。Clears the collection of any members. |
CopyTo(Array, Int32) |
現在の 1 次元 Array のすべての要素を、指定した 1 次元 Array に Array の指定したコピー先インデックスを開始位置としてコピーします。Copies all the elements of the current one-dimensional Array to the specified one-dimensional Array starting at the specified destination Array index. (継承元 BaseCollection) |
CreateObjRef(Type) |
リモート オブジェクトとの通信に使用するプロキシの生成に必要な情報をすべて格納しているオブジェクトを作成します。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (継承元 MarshalByRefObject) |
Equals(Object) |
指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。Determines whether the specified object is equal to the current object. (継承元 Object) |
GetEnumerator() |
コレクションのメンバーを反復処理できるオブジェクトを取得します。Gets the object that enables iterating through the members of the collection. (継承元 BaseCollection) |
GetHashCode() |
既定のハッシュ関数として機能します。Serves as the default hash function. (継承元 Object) |
GetLifetimeService() |
対象のインスタンスの有効期間ポリシーを制御する、現在の有効期間サービス オブジェクトを取得します。Retrieves the current lifetime service object that controls the lifetime policy for this instance. (継承元 MarshalByRefObject) |
GetType() |
現在のインスタンスの Type を取得します。Gets the Type of the current instance. (継承元 Object) |
InitializeLifetimeService() |
このインスタンスの有効期間ポリシーを制御する有効期間サービス オブジェクトを取得します。Obtains a lifetime service object to control the lifetime policy for this instance. (継承元 MarshalByRefObject) |
MemberwiseClone() |
現在の Object の簡易コピーを作成します。Creates a shallow copy of the current Object. (継承元 Object) |
MemberwiseClone(Boolean) |
現在の MarshalByRefObject オブジェクトの簡易コピーを作成します。Creates a shallow copy of the current MarshalByRefObject object. (継承元 MarshalByRefObject) |
OnCollectionChanged(CollectionChangeEventArgs) |
CollectionChanged イベントを発生させます。Raises the CollectionChanged event. |
OnCollectionChanging(CollectionChangeEventArgs) |
CollectionChanging イベントを発生させます。Raises the CollectionChanging event. |
Remove(Binding) |
指定したバインディングをコレクションから削除します。Deletes the specified binding from the collection. |
RemoveAt(Int32) |
指定したインデック位置のバインディングをコレクションから削除します。Deletes the binding from the collection at the specified index. |
RemoveCore(Binding) |
指定された Binding をコレクションから削除します。Removes the specified Binding from the collection. |
ShouldSerializeMyAll() |
コレクションをシリアル化する必要があるかどうかを示す値を取得します。Gets a value that indicates whether the collection should be serialized. |
ToString() |
現在のオブジェクトを表す文字列を返します。Returns a string that represents the current object. (継承元 Object) |
イベント
CollectionChanged |
コレクションが変更されたときに発生します。Occurs when the collection has changed. |
CollectionChanging |
コレクションが変更される直前に発生します。Occurs when the collection is about to change. |
拡張メソッド
Cast<TResult>(IEnumerable) |
IEnumerable の要素を、指定した型にキャストします。Casts the elements of an IEnumerable to the specified type. |
OfType<TResult>(IEnumerable) |
指定された型に基づいて IEnumerable の要素をフィルター処理します。Filters the elements of an IEnumerable based on a specified type. |
AsParallel(IEnumerable) |
クエリの並列化を有効にします。Enables parallelization of a query. |
AsQueryable(IEnumerable) |
IEnumerable を IQueryable に変換します。Converts an IEnumerable to an IQueryable. |