次の方法で共有


ControlBindingsCollection.Add メソッド

定義

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

オーバーロード

名前 説明
Add(Binding)

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

Add(String, Object, String)

指定したコントロール プロパティ名、データ ソース、およびデータ メンバーを使用して Binding を作成し、コレクションに追加します。

Add(String, Object, String, Boolean)

指定したコントロール プロパティ名、データ ソース、データ メンバー、および書式設定が有効になっているかどうかに関する情報を使用してバインディングを作成し、バインディングをコレクションに追加します。

Add(String, Object, String, Boolean, DataSourceUpdateMode)

指定したコントロール プロパティを指定したデータ ソースの指定されたデータ メンバーにバインドするバインドを作成します。必要に応じて、書式設定を有効にし、指定した更新設定に基づいてデータ ソースに値を伝達し、コレクションにバインドを追加します。

Add(String, Object, String, Boolean, DataSourceUpdateMode, Object)

指定したコントロール プロパティを指定したデータ ソースの指定されたデータ メンバーにバインドするバインディングを作成します。必要に応じて、書式設定を有効にし、指定した更新設定に基づいてデータ ソースに値を伝達し、データ ソースから DBNull が返されたときにプロパティを指定した値に設定し、バインディングをコレクションに追加します。

Add(String, Object, String, Boolean, DataSourceUpdateMode, Object, String)

指定したコントロール プロパティを指定したデータ ソースの指定されたデータ メンバーにバインドするバインドを作成します。必要に応じて、指定した書式指定文字列を使用して書式設定を有効にし、指定した更新設定に基づいてデータ ソースに値を伝達し、データ ソースから DBNull が返されたときにプロパティを指定した値に設定し、バインディングをコレクションに追加します。

Add(String, Object, String, Boolean, DataSourceUpdateMode, Object, String, IFormatProvider)

指定したコントロール プロパティを指定したデータ ソースの指定されたデータ メンバーにバインドするバインディングを作成します。必要に応じて、指定した書式指定文字列を使用して書式設定を有効にし、指定した更新設定に基づいてデータ ソースに値を伝達し、データ ソースから DBNull が返されたときにプロパティを指定した値に設定し、指定した書式プロバイダーを設定します。 バインディングをコレクションに追加します。

Add(Binding)

ソース:
ControlBindingsCollection.cs
ソース:
ControlBindingsCollection.cs
ソース:
ControlBindingsCollection.cs
ソース:
ControlBindingsCollection.cs
ソース:
ControlBindingsCollection.cs

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

public:
 void Add(System::Windows::Forms::Binding ^ binding);
public void Add(System.Windows.Forms.Binding binding);
override this.Add : System.Windows.Forms.Binding -> unit
Public Sub Add (binding As Binding)

パラメーター

binding
Binding

追加する Binding

例外

bindingは null です。

コントロール プロパティは既にデータ バインドされています。

-又は-

Bindingでは、DataSourceの有効な列が指定されていません。

次のコード例では、Binding インスタンスを作成し、Add メソッドを使用して、TextBox コントロールのControlBindingsCollectionにインスタンスを追加します。

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 = gcnew Binding(
         "Text",ds,"customers.custToOrders.OrderAmount" );
      b->Parse += gcnew ConvertEventHandler(
         this, &Form1::CurrencyStringToDecimal );
      b->Format += gcnew ConvertEventHandler(
         this, &Form1::DecimalToCurrencyString );
      textBox1->DataBindings->Add( b );
   }
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);
}
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

注釈

Add メソッドのこのオーバーロードによって作成されるBindingDataSourceUpdateMode プロパティは、DefaultDataSourceUpdateMode プロパティの値に設定されます。

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

適用対象

Add(String, Object, String)

ソース:
ControlBindingsCollection.cs
ソース:
ControlBindingsCollection.cs
ソース:
ControlBindingsCollection.cs
ソース:
ControlBindingsCollection.cs
ソース:
ControlBindingsCollection.cs

指定したコントロール プロパティ名、データ ソース、およびデータ メンバーを使用して Binding を作成し、コレクションに追加します。

public:
 System::Windows::Forms::Binding ^ Add(System::String ^ propertyName, System::Object ^ dataSource, System::String ^ dataMember);
public System.Windows.Forms.Binding Add(string propertyName, object dataSource, string dataMember);
public System.Windows.Forms.Binding Add(string propertyName, object dataSource, string? dataMember);
override this.Add : string * obj * string -> System.Windows.Forms.Binding
Public Function Add (propertyName As String, dataSource As Object, dataMember As String) As Binding

パラメーター

propertyName
String

バインドするコントロール プロパティの名前。

dataSource
Object

データ ソースを表す Object

dataMember
String

バインドするプロパティまたはリスト。

戻り値

新しく作成された Binding

例外

bindingnull です。

propertyNameは既にデータ バインドされています。

-又は-

dataMemberでは、dataSourceの有効なメンバーが指定されていません。

次のコード例では、Add メソッドを使用して、TextBox コントロールのControlBindingsCollectionに 3 つのBinding オブジェクトを追加します。 ControlBindingsCollectionは、Control クラスの DataBindings プロパティを介してアクセスされます。

private:
   void BindTextBoxProperties()
   {
      // Clear the collection before adding new Binding objects.
      textBox1->DataBindings->Clear();

      // Create a DataTable containing Color objects.
      DataTable^ t = MakeTable();

      /* Bind the Text, BackColor, and ForeColor properties
         to columns in the DataTable. */
      textBox1->DataBindings->Add( "Text", t, "Text" );
      textBox1->DataBindings->Add( "BackColor", t, "BackColor" );
      textBox1->DataBindings->Add( "ForeColor", t, "ForeColor" );
   }

   DataTable^ MakeTable()
   {
      /* Create a DataTable with three columns.
         Two of the columns contain Color objects. */
      DataTable^ t = gcnew DataTable( "Control" );
      t->Columns->Add( "BackColor", Color::typeid );
      t->Columns->Add( "ForeColor", Color::typeid );
      t->Columns->Add( "Text" );

      // Add three rows to the table.
      DataRow^ r;
      r = t->NewRow();
      r[ "BackColor" ] = Color::Blue;
      r[ "ForeColor" ] = Color::Yellow;
      r[ "Text" ] = "Yellow on Blue";
      t->Rows->Add( r );
      r = t->NewRow();
      r[ "BackColor" ] = Color::White;
      r[ "ForeColor" ] = Color::Green;
      r[ "Text" ] = "Green on white";
      t->Rows->Add( r );
      r = t->NewRow();
      r[ "BackColor" ] = Color::Orange;
      r[ "ForeColor" ] = Color::Black;
      r[ "Text" ] = "Black on Orange";
      t->Rows->Add( r );
      return t;
   }
private void BindTextBoxProperties()
{
   // Clear the collection before adding new Binding objects.
   textBox1.DataBindings.Clear();

   // Create a DataTable containing Color objects.
   DataTable t = MakeTable();

   /* Bind the Text, BackColor, and ForeColor properties
   to columns in the DataTable. */
   textBox1.DataBindings.Add("Text", t, "Text");
   textBox1.DataBindings.Add("BackColor", t, "BackColor");
   textBox1.DataBindings.Add("ForeColor", t, "ForeColor");
}

private DataTable MakeTable()
{
   /* Create a DataTable with three columns.
   Two of the columns contain Color objects. */

   DataTable t = new DataTable("Control");
   t.Columns.Add("BackColor", typeof(Color));
   t.Columns.Add("ForeColor", typeof(Color));
   t.Columns.Add("Text");

   // Add three rows to the table.
   DataRow r;

   r = t.NewRow();
   r["BackColor"] = Color.Blue;
   r["ForeColor"] = Color.Yellow;
   r["Text"] = "Yellow on Blue";
   t.Rows.Add(r);

   r = t.NewRow();
   r["BackColor"] = Color.White;
   r["ForeColor"] = Color.Green;
   r["Text"] = "Green on white";
   t.Rows.Add(r);

   r = t.NewRow();
   r["BackColor"] = Color.Orange;
   r["ForeColor"] = Color.Black;
   r["Text"] = "Black on Orange";
   t.Rows.Add(r);

   return t;
}
Private Sub BindTextBoxProperties()
    ' Clear the collection before adding new Binding objects.
    textBox1.DataBindings.Clear()
    
    ' Create a DataTable containing Color objects.
    Dim t As DataTable = MakeTable()
    
    ' Bind the Text, BackColor, and ForeColor properties
    ' to columns in the DataTable. 
    textBox1.DataBindings.Add("Text", t, "Text")
    textBox1.DataBindings.Add("BackColor", t, "BackColor")
    textBox1.DataBindings.Add("ForeColor", t, "ForeColor")
End Sub    

Private Function MakeTable() As DataTable
    ' Create a DataTable with three columns.
    ' Two of the columns contain Color objects. 
    
    Dim t As New DataTable("Control")
    t.Columns.Add("BackColor", GetType(Color))
    t.Columns.Add("ForeColor", GetType(Color))
    t.Columns.Add("Text")
    
    ' Add three rows to the table.
    Dim r As DataRow
    
    r = t.NewRow()
    r("BackColor") = Color.Blue
    r("ForeColor") = Color.Yellow
    r("Text") = "Yellow on Blue"
    t.Rows.Add(r)
    
    r = t.NewRow()
    r("BackColor") = Color.White
    r("ForeColor") = Color.Green
    r("Text") = "Green on white"
    t.Rows.Add(r)
    
    r = t.NewRow()
    r("BackColor") = Color.Orange
    r("ForeColor") = Color.Black
    r("Text") = "Black on Orange"
    t.Rows.Add(r)
    
    Return t
End Function

注釈

Add メソッドのこのオーバーロードによって作成されるBindingDataSourceUpdateMode プロパティは、DefaultDataSourceUpdateMode プロパティの値に設定されます。

Bindingを追加すると、CollectionChanged イベントが発生します。

適用対象

Add(String, Object, String, Boolean)

ソース:
ControlBindingsCollection.cs
ソース:
ControlBindingsCollection.cs
ソース:
ControlBindingsCollection.cs
ソース:
ControlBindingsCollection.cs
ソース:
ControlBindingsCollection.cs

指定したコントロール プロパティ名、データ ソース、データ メンバー、および書式設定が有効になっているかどうかに関する情報を使用してバインディングを作成し、バインディングをコレクションに追加します。

public:
 System::Windows::Forms::Binding ^ Add(System::String ^ propertyName, System::Object ^ dataSource, System::String ^ dataMember, bool formattingEnabled);
public System.Windows.Forms.Binding Add(string propertyName, object dataSource, string dataMember, bool formattingEnabled);
public System.Windows.Forms.Binding Add(string propertyName, object dataSource, string? dataMember, bool formattingEnabled);
override this.Add : string * obj * string * bool -> System.Windows.Forms.Binding
Public Function Add (propertyName As String, dataSource As Object, dataMember As String, formattingEnabled As Boolean) As Binding

パラメーター

propertyName
String

バインドするコントロール プロパティの名前。

dataSource
Object

データ ソースを表す Object

dataMember
String

バインドするプロパティまたはリスト。

formattingEnabled
Boolean

true 表示されるデータの書式を設定する。それ以外の場合は false

戻り値

新しく作成された Binding

例外

propertyNameによって指定されたプロパティがコントロールに存在しません。

-又は-

指定されたプロパティは読み取り専用プロパティです。

書式設定が無効で、 propertyName がコントロールの有効なプロパティでも空の文字列 ("") でもない場合。

適用対象

Add(String, Object, String, Boolean, DataSourceUpdateMode)

ソース:
ControlBindingsCollection.cs
ソース:
ControlBindingsCollection.cs
ソース:
ControlBindingsCollection.cs
ソース:
ControlBindingsCollection.cs
ソース:
ControlBindingsCollection.cs

指定したコントロール プロパティを指定したデータ ソースの指定されたデータ メンバーにバインドするバインドを作成します。必要に応じて、書式設定を有効にし、指定した更新設定に基づいてデータ ソースに値を伝達し、コレクションにバインドを追加します。

public:
 System::Windows::Forms::Binding ^ Add(System::String ^ propertyName, System::Object ^ dataSource, System::String ^ dataMember, bool formattingEnabled, System::Windows::Forms::DataSourceUpdateMode updateMode);
public System.Windows.Forms.Binding Add(string propertyName, object dataSource, string dataMember, bool formattingEnabled, System.Windows.Forms.DataSourceUpdateMode updateMode);
public System.Windows.Forms.Binding Add(string propertyName, object dataSource, string? dataMember, bool formattingEnabled, System.Windows.Forms.DataSourceUpdateMode updateMode);
override this.Add : string * obj * string * bool * System.Windows.Forms.DataSourceUpdateMode -> System.Windows.Forms.Binding
Public Function Add (propertyName As String, dataSource As Object, dataMember As String, formattingEnabled As Boolean, updateMode As DataSourceUpdateMode) As Binding

パラメーター

propertyName
String

バインドするコントロール プロパティの名前。

dataSource
Object

データ ソースを表す Object

dataMember
String

バインドするプロパティまたはリスト。

formattingEnabled
Boolean

true 表示されるデータの書式を設定する。それ以外の場合は false

updateMode
DataSourceUpdateMode

DataSourceUpdateMode値の 1 つ。

戻り値

新しく作成された Binding

例外

propertyNameによって指定されたプロパティがコントロールに存在しないか、読み取り専用です。

-又は-

指定されたデータ メンバーがデータ ソースに存在しません。

-又は-

指定されたデータ ソース、データ メンバー、またはコントロール プロパティは、コレクション内の別のバインディングに関連付けられます。

注釈

Add メソッドを呼び出すと、CollectionChanged イベントが発生します。

適用対象

Add(String, Object, String, Boolean, DataSourceUpdateMode, Object)

ソース:
ControlBindingsCollection.cs
ソース:
ControlBindingsCollection.cs
ソース:
ControlBindingsCollection.cs
ソース:
ControlBindingsCollection.cs
ソース:
ControlBindingsCollection.cs

指定したコントロール プロパティを指定したデータ ソースの指定されたデータ メンバーにバインドするバインディングを作成します。必要に応じて、書式設定を有効にし、指定した更新設定に基づいてデータ ソースに値を伝達し、データ ソースから DBNull が返されたときにプロパティを指定した値に設定し、バインディングをコレクションに追加します。

public:
 System::Windows::Forms::Binding ^ Add(System::String ^ propertyName, System::Object ^ dataSource, System::String ^ dataMember, bool formattingEnabled, System::Windows::Forms::DataSourceUpdateMode updateMode, System::Object ^ nullValue);
public System.Windows.Forms.Binding Add(string propertyName, object dataSource, string dataMember, bool formattingEnabled, System.Windows.Forms.DataSourceUpdateMode updateMode, object nullValue);
public System.Windows.Forms.Binding Add(string propertyName, object dataSource, string? dataMember, bool formattingEnabled, System.Windows.Forms.DataSourceUpdateMode updateMode, object? nullValue);
override this.Add : string * obj * string * bool * System.Windows.Forms.DataSourceUpdateMode * obj -> System.Windows.Forms.Binding
Public Function Add (propertyName As String, dataSource As Object, dataMember As String, formattingEnabled As Boolean, updateMode As DataSourceUpdateMode, nullValue As Object) As Binding

パラメーター

propertyName
String

バインドするコントロール プロパティの名前。

dataSource
Object

データ ソースを表す Object

dataMember
String

バインドするプロパティまたはリスト。

formattingEnabled
Boolean

true 表示されるデータの書式を設定する。それ以外の場合は false

updateMode
DataSourceUpdateMode

DataSourceUpdateMode値の 1 つ。

nullValue
Object

データ ソースにこの値がある場合、バインドされたプロパティは DBNullに設定されます。

戻り値

新しく作成された Binding

例外

propertyNameによって指定されたプロパティがコントロールに存在しないか、読み取り専用です。

-又は-

指定されたデータ メンバーがデータ ソースに存在しません。

-又は-

指定されたデータ ソース、データ メンバー、またはコントロール プロパティは、コレクション内の別のバインディングに関連付けられます。

注釈

Add メソッドを呼び出すと、CollectionChanged イベントが発生します。

適用対象

Add(String, Object, String, Boolean, DataSourceUpdateMode, Object, String)

ソース:
ControlBindingsCollection.cs
ソース:
ControlBindingsCollection.cs
ソース:
ControlBindingsCollection.cs
ソース:
ControlBindingsCollection.cs
ソース:
ControlBindingsCollection.cs

指定したコントロール プロパティを指定したデータ ソースの指定されたデータ メンバーにバインドするバインドを作成します。必要に応じて、指定した書式指定文字列を使用して書式設定を有効にし、指定した更新設定に基づいてデータ ソースに値を伝達し、データ ソースから DBNull が返されたときにプロパティを指定した値に設定し、バインディングをコレクションに追加します。

public:
 System::Windows::Forms::Binding ^ Add(System::String ^ propertyName, System::Object ^ dataSource, System::String ^ dataMember, bool formattingEnabled, System::Windows::Forms::DataSourceUpdateMode updateMode, System::Object ^ nullValue, System::String ^ formatString);
public System.Windows.Forms.Binding Add(string propertyName, object dataSource, string dataMember, bool formattingEnabled, System.Windows.Forms.DataSourceUpdateMode updateMode, object nullValue, string formatString);
public System.Windows.Forms.Binding Add(string propertyName, object dataSource, string? dataMember, bool formattingEnabled, System.Windows.Forms.DataSourceUpdateMode updateMode, object? nullValue, string formatString);
override this.Add : string * obj * string * bool * System.Windows.Forms.DataSourceUpdateMode * obj * string -> System.Windows.Forms.Binding
Public Function Add (propertyName As String, dataSource As Object, dataMember As String, formattingEnabled As Boolean, updateMode As DataSourceUpdateMode, nullValue As Object, formatString As String) As Binding

パラメーター

propertyName
String

バインドするコントロール プロパティの名前。

dataSource
Object

データ ソースを表す Object

dataMember
String

バインドするプロパティまたはリスト。

formattingEnabled
Boolean

true 表示されるデータの書式を設定する。それ以外の場合は false

updateMode
DataSourceUpdateMode

DataSourceUpdateMode値の 1 つ。

nullValue
Object

データ ソースにこの値がある場合、バインドされたプロパティは DBNullに設定されます。

formatString
String

値の表示方法を示す 1 つ以上の書式指定子文字。

戻り値

新しく作成された Binding

例外

propertyNameによって指定されたプロパティがコントロールに存在しないか、読み取り専用です。

-又は-

指定されたデータ メンバーがデータ ソースに存在しません。

-又は-

指定されたデータ ソース、データ メンバー、またはコントロール プロパティは、コレクション内の別のバインディングに関連付けられます。

注釈

Add メソッドを呼び出すと、CollectionChanged イベントが発生します。

適用対象

Add(String, Object, String, Boolean, DataSourceUpdateMode, Object, String, IFormatProvider)

ソース:
ControlBindingsCollection.cs
ソース:
ControlBindingsCollection.cs
ソース:
ControlBindingsCollection.cs
ソース:
ControlBindingsCollection.cs
ソース:
ControlBindingsCollection.cs

指定したコントロール プロパティを指定したデータ ソースの指定されたデータ メンバーにバインドするバインディングを作成します。必要に応じて、指定した書式指定文字列を使用して書式設定を有効にし、指定した更新設定に基づいてデータ ソースに値を伝達し、データ ソースから DBNull が返されたときにプロパティを指定した値に設定し、指定した書式プロバイダーを設定します。 バインディングをコレクションに追加します。

public:
 System::Windows::Forms::Binding ^ Add(System::String ^ propertyName, System::Object ^ dataSource, System::String ^ dataMember, bool formattingEnabled, System::Windows::Forms::DataSourceUpdateMode updateMode, System::Object ^ nullValue, System::String ^ formatString, IFormatProvider ^ formatInfo);
public System.Windows.Forms.Binding Add(string propertyName, object dataSource, string dataMember, bool formattingEnabled, System.Windows.Forms.DataSourceUpdateMode updateMode, object nullValue, string formatString, IFormatProvider formatInfo);
public System.Windows.Forms.Binding Add(string propertyName, object dataSource, string? dataMember, bool formattingEnabled, System.Windows.Forms.DataSourceUpdateMode updateMode, object? nullValue, string formatString, IFormatProvider? formatInfo);
override this.Add : string * obj * string * bool * System.Windows.Forms.DataSourceUpdateMode * obj * string * IFormatProvider -> System.Windows.Forms.Binding
Public Function Add (propertyName As String, dataSource As Object, dataMember As String, formattingEnabled As Boolean, updateMode As DataSourceUpdateMode, nullValue As Object, formatString As String, formatInfo As IFormatProvider) As Binding

パラメーター

propertyName
String

バインドするコントロール プロパティの名前。

dataSource
Object

データ ソースを表す Object

dataMember
String

バインドするプロパティまたはリスト。

formattingEnabled
Boolean

true 表示されるデータの書式を設定する。それ以外の場合は false

updateMode
DataSourceUpdateMode

DataSourceUpdateMode値の 1 つ。

nullValue
Object

データ ソースにこの値がある場合、バインドされたプロパティは DBNullに設定されます。

formatString
String

値の表示方法を示す 1 つ以上の書式指定子文字。

formatInfo
IFormatProvider

既定の書式設定動作をオーバーライドする IFormatProvider の実装。

戻り値

新しく作成された Binding

例外

propertyNameによって指定されたプロパティがコントロールに存在しないか、読み取り専用です。

-又は-

指定されたデータ メンバーがデータ ソースに存在しません。

-又は-

指定されたデータ ソース、データ メンバー、またはコントロール プロパティは、コレクション内の別のバインディングに関連付けられます。

注釈

Add メソッドを呼び出すと、CollectionChanged イベントが発生します。

適用対象