次の方法で共有


ControlBindingsCollection.Add メソッド (Binding)

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

Overloads Public Shadows Sub Add( _
   ByVal binding As Binding _)
[C#]
public new void Add(Bindingbinding);
[C++]
public: void Add(Binding* binding);
[JScript]
public hide function Add(
   binding : Binding);

パラメータ

例外

例外の種類 条件
ArgumentNullException binding が null です。
Exception コントロール プロパティが既にデータ連結されています。
Exception Binding オブジェクトが、 DataSource の有効な列を指定していません。

解説

CollectionChanged イベントは、変更が完了すると発生します。

使用例

[Visual Basic, C#, C++] Binding インスタンスを作成し、 Add メソッドを使用して、このインスタンスを TextBox コントロールの ControlBindingsCollection に追加する例を次に示します。

 
Protected Sub BindControls()
    ' 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
    textBox1.DataBindings.Add(b)
End Sub    

[C#] 
protected void BindControls()
{
   /* 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);
   textBox1.DataBindings.Add(b);
}

[C++] 
protected:
void BindControls()
{
   /* 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(S"Text", ds, S"customers.custToOrders.OrderAmount");
   b->Parse+=new ConvertEventHandler(this, &Form1::CurrencyStringToDecimal);
   b->Format+=new ConvertEventHandler(this, &Form1::DecimalToCurrencyString);
   textBox1->DataBindings->Add(b);
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

参照

ControlBindingsCollection クラス | ControlBindingsCollection メンバ | System.Windows.Forms 名前空間 | ControlBindingsCollection.Add オーバーロードの一覧