BindingsCollection クラス

定義

コントロールの Binding オブジェクトのコレクションを表します。

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 データベース内のフィールドにバインドします。

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

注釈

単純なデータ バインディングは、 にオブジェクトをBindingsCollection追加Bindingすることによって実現されます。 クラスから継承するすべてのオブジェクトは、 Control プロパティを介して にBindingsCollectionDataBindingsアクセスできます。 データ バインディングをサポートする Windows コントロールの一覧については、 クラスを Binding 参照してください。

プロパティ

Count

コレクション内のバインディングの合計数を取得します。

IsReadOnly

コレクションが読み取り専用かどうかを示す値を取得します。

(継承元 BaseCollection)
IsSynchronized

ICollection へのアクセスの同期がとられているかどうかを示す値を取得します。

(継承元 BaseCollection)
Item[Int32]

指定されたインデックス位置にある Binding を取得します。

List

コレクション内のバインディングをオブジェクトとして取得します。

SyncRoot

BaseCollection へのアクセスを同期するために使用できるオブジェクトを取得します。

(継承元 BaseCollection)

メソッド

Add(Binding)

指定したバインディングをコレクションに追加します。

AddCore(Binding)

Binding をコレクションに追加します。

Clear()

バインディング オブジェクトのコレクションを削除します。

ClearCore()

メンバーのコレクションを消去します。

CopyTo(Array, Int32)

現在の 1 次元 Array のすべての要素を、指定した 1 次元 ArrayArray の指定したコピー先インデックスを開始位置としてコピーします。

(継承元 BaseCollection)
CreateObjRef(Type)

リモート オブジェクトとの通信に使用するプロキシの生成に必要な情報をすべて格納しているオブジェクトを作成します。

(継承元 MarshalByRefObject)
Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetEnumerator()

コレクションのメンバーを反復処理できるオブジェクトを取得します。

(継承元 BaseCollection)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetLifetimeService()
古い.

対象のインスタンスの有効期間ポリシーを制御する、現在の有効期間サービス オブジェクトを取得します。

(継承元 MarshalByRefObject)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
InitializeLifetimeService()
古い.

このインスタンスの有効期間ポリシーを制御する有効期間サービス オブジェクトを取得します。

(継承元 MarshalByRefObject)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
MemberwiseClone(Boolean)

現在の MarshalByRefObject オブジェクトの簡易コピーを作成します。

(継承元 MarshalByRefObject)
OnCollectionChanged(CollectionChangeEventArgs)

CollectionChanged イベントを発生させます。

OnCollectionChanging(CollectionChangeEventArgs)

CollectionChanging イベントを発生させます。

Remove(Binding)

指定したバインディングをコレクションから削除します。

RemoveAt(Int32)

指定したインデック位置のバインディングをコレクションから削除します。

RemoveCore(Binding)

指定された Binding をコレクションから削除します。

ShouldSerializeMyAll()

コレクションをシリアル化する必要があるかどうかを示す値を取得します。

ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

イベント

CollectionChanged

コレクションが変更されたときに発生します。

CollectionChanging

コレクションが変更される直前に発生します。

拡張メソッド

Cast<TResult>(IEnumerable)

IEnumerable の要素を、指定した型にキャストします。

OfType<TResult>(IEnumerable)

指定された型に基づいて IEnumerable の要素をフィルター処理します。

AsParallel(IEnumerable)

クエリの並列化を有効にします。

AsQueryable(IEnumerable)

IEnumerableIQueryable に変換します。

適用対象

こちらもご覧ください