BindingsCollection イベント
BindingsCollection クラス
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)


単純なデータ連結は、Binding オブジェクトを BindingsCollection に追加することによって実行されます。Control クラスから継承される任意のオブジェクトは、DataBindings プロパティを使用して BindingsCollection にアクセスできます。データ連結をサポートする Windows コントロールの一覧については、Binding クラスのトピックを参照してください。

TextBox コントロールの Text プロパティをデータベース内のフィールドにバインドする例を次に示します。
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
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: 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.add_Parse(new ConvertEventHandler(CurrencyToDecimal)); myBinding.add_Format(new ConvertEventHandler(DecimalToCurrency)); // Adds the new Binding to the BindingsCollection. text1.get_DataBindings().Add(myBinding); } //BindTextBoxControl 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.set_Value(((System.Decimal)(cevent.get_Value())).ToString("c")); } //DecimalToCurrency 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.set_Value(Decimal.Parse(cevent.get_Value().ToString(), NumberStyles.Currency, null)); } //CurrencyToDecimal

System.MarshalByRefObject
System.Windows.Forms.BaseCollection
System.Windows.Forms.BindingsCollection
System.Windows.Forms.ControlBindingsCollection


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


BindingsCollection プロパティ

名前 | 説明 | |
---|---|---|
![]() | Count | オーバーライドされます。 コレクション内のバインディングの合計数を取得します。 |
![]() | IsReadOnly | コレクションが読み取り専用かどうかを示す値を取得します。 ( BaseCollection から継承されます。) |
![]() | IsSynchronized | ICollection へのアクセスの同期がとられているかどうかを示す値を取得します。 ( BaseCollection から継承されます。) |
![]() | SyncRoot | BaseCollection へのアクセスを同期するために使用できるオブジェクトを取得します。 ( BaseCollection から継承されます。) |


BindingsCollection メソッド

名前 | 説明 | |
---|---|---|
![]() | CopyTo | 指定したコピー先の Array インデックスを開始位置として、現在の 1 次元 Array のすべての要素を指定した 1 次元 Array にコピーします。 ( BaseCollection から継承されます。) |
![]() | CreateObjRef | リモート オブジェクトとの通信に使用するプロキシの生成に必要な情報をすべて格納しているオブジェクトを作成します。 ( MarshalByRefObject から継承されます。) |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetEnumerator | コレクションのメンバを反復処理できるオブジェクトを取得します。 ( BaseCollection から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetLifetimeService | 対象のインスタンスの有効期間ポリシーを制御する、現在の有効期間サービス オブジェクトを取得します。 ( MarshalByRefObject から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | InitializeLifetimeService | 対象のインスタンスの有効期間ポリシーを制御する、有効期間サービス オブジェクトを取得します。 ( MarshalByRefObject から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Add | 指定したバインディングをコレクションに追加します。 |
![]() | AddCore | Binding をコレクションに追加します。 |
![]() | Clear | バインディング オブジェクトのコレクションを削除します。 |
![]() | ClearCore | メンバのコレクションを消去します。 |
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | オーバーロードされます。 ( MarshalByRefObject から継承されます。) |
![]() | OnCollectionChanged | CollectionChanged イベントを発生させます。 |
![]() | OnCollectionChanging | CollectionChanging イベントを発生させます。 |
![]() | Remove | 指定したバインディングをコレクションから削除します。 |
![]() | RemoveAt | 指定したインデック位置のバインディングをコレクションから削除します。 |
![]() | RemoveCore | 指定した Binding をコレクションから削除します。 |
![]() | ShouldSerializeMyAll | コレクションをシリアル化する必要があるかどうかを示す値を取得します。 |

BindingsCollection メンバ
コントロールの Binding オブジェクトのコレクションを表します。
BindingsCollection データ型で公開されるメンバを以下の表に示します。

名前 | 説明 | |
---|---|---|
![]() | Count | オーバーライドされます。 コレクション内のバインディングの合計数を取得します。 |
![]() | IsReadOnly | コレクションが読み取り専用かどうかを示す値を取得します。(BaseCollection から継承されます。) |
![]() | IsSynchronized | ICollection へのアクセスの同期がとられているかどうかを示す値を取得します。(BaseCollection から継承されます。) |
![]() | SyncRoot | BaseCollection へのアクセスを同期するために使用できるオブジェクトを取得します。(BaseCollection から継承されます。) |


名前 | 説明 | |
---|---|---|
![]() | CopyTo | 指定したコピー先の Array インデックスを開始位置として、現在の 1 次元 Array のすべての要素を指定した 1 次元 Array にコピーします。 (BaseCollection から継承されます。) |
![]() | CreateObjRef | リモート オブジェクトとの通信に使用するプロキシの生成に必要な情報をすべて格納しているオブジェクトを作成します。 (MarshalByRefObject から継承されます。) |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetEnumerator | コレクションのメンバを反復処理できるオブジェクトを取得します。 (BaseCollection から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetLifetimeService | 対象のインスタンスの有効期間ポリシーを制御する、現在の有効期間サービス オブジェクトを取得します。 (MarshalByRefObject から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | InitializeLifetimeService | 対象のインスタンスの有効期間ポリシーを制御する、有効期間サービス オブジェクトを取得します。 (MarshalByRefObject から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Add | 指定したバインディングをコレクションに追加します。 |
![]() | AddCore | Binding をコレクションに追加します。 |
![]() | Clear | バインディング オブジェクトのコレクションを削除します。 |
![]() | ClearCore | メンバのコレクションを消去します。 |
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | オーバーロードされます。 ( MarshalByRefObject から継承されます。) |
![]() | OnCollectionChanged | CollectionChanged イベントを発生させます。 |
![]() | OnCollectionChanging | CollectionChanging イベントを発生させます。 |
![]() | Remove | 指定したバインディングをコレクションから削除します。 |
![]() | RemoveAt | 指定したインデック位置のバインディングをコレクションから削除します。 |
![]() | RemoveCore | 指定した Binding をコレクションから削除します。 |
![]() | ShouldSerializeMyAll | コレクションをシリアル化する必要があるかどうかを示す値を取得します。 |


- BindingsCollectionのページへのリンク