BindingSource.DataSource プロパティ

定義

コネクタのバインド先であるデータ ソースを取得または設定します。

public:
 property System::Object ^ DataSource { System::Object ^ get(); void set(System::Object ^ value); };
public object DataSource { get; set; }
public object? DataSource { get; set; }
member this.DataSource : obj with get, set
Public Property DataSource As Object

プロパティ値

データ ソースとして機能する Object。 既定値は、null です。

次のコード例では、コンポーネントの に顧客の一覧をDataSourceBindingSource割り当てます。 このコード例は、「 方法: BindingSource ResetItem メソッドを使用して変更通知を発生させる」で提供される大きな例の一部です。

void Form1_Load( Object^ /*sender*/, EventArgs^ /*e*/ )
{
   // Create and populate the list of DemoCustomer objects
   // which will supply data to the DataGridView.
   List< DemoCustomer^ >^ customerList = gcnew List< DemoCustomer^ >;
   customerList->Add( DemoCustomer::CreateNewCustomer() );
   customerList->Add( DemoCustomer::CreateNewCustomer() );
   customerList->Add( DemoCustomer::CreateNewCustomer() );
   
   // Bind the list to the BindingSource.
   this->customersBindingSource->DataSource = customerList;
   
   // Attach the BindingSource to the DataGridView.
   this->customersDataGridView->DataSource =
      this->customersBindingSource;
}
private void Form1_Load(System.Object sender, System.EventArgs e)
{
    // Create and populate the list of DemoCustomer objects
    // which will supply data to the DataGridView.
    List<DemoCustomer> customerList = new List<DemoCustomer>();
    customerList.Add(DemoCustomer.CreateNewCustomer());
    customerList.Add(DemoCustomer.CreateNewCustomer());
    customerList.Add(DemoCustomer.CreateNewCustomer());

    // Bind the list to the BindingSource.
    this.customersBindingSource.DataSource = customerList;

    // Attach the BindingSource to the DataGridView.
    this.customersDataGridView.DataSource = 
        this.customersBindingSource;
}
Private Sub Form1_Load(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Me.Load
    ' Create and populate the list of DemoCustomer objects
    ' which will supply data to the DataGridView.
    Dim customerList As List(Of DemoCustomer) = _
    New List(Of DemoCustomer)
    customerList.Add(DemoCustomer.CreateNewCustomer())
    customerList.Add(DemoCustomer.CreateNewCustomer())
    customerList.Add(DemoCustomer.CreateNewCustomer())

    ' Bind the list to the BindingSource.
    Me.customersBindingSource.DataSource = customerList

    ' Attach the BindingSource to the DataGridView.
    Me.customersDataGridView.DataSource = Me.customersBindingSource
End Sub

注釈

プロパティは DataSource 、型、オブジェクト、型のリストなど、さまざまなデータ ソースに設定できます。 結果として得られるデータ ソースはリストとして公開されます。 次の表は、いくつかの一般的なデータ ソースと結果のリストの評価を示しています。

DataSource プロパティ リスト結果
null オブジェクトの空の IBindingList。 項目を追加すると、追加した項目の型にリストが設定されます。
nullset DataMember サポートされていません。 は を発生させます ArgumentException
リスト以外の型または型 "T" のオブジェクト 型 "T" が空 IBindingList です。
配列インスタンス IBindingList 配列要素を格納しています。
IEnumerable インスタンス IBindingList項目を格納している IEnumerable
型 "T" を含むリスト インスタンス IBindingList 型 "T" を含む インスタンス。

さらに、 DataSource を や などのIListSourceITypedList他のリスト型に設定すると、 BindingSource によって適切に処理されます。 この場合、リストに含まれる型にはパラメーターなしのコンストラクターが必要です。

データ ソースを設定するときに、指定された参照に複数のリストまたはテーブルが含まれている場合は、 プロパティを DataMember バインド先のリストを指定する文字列に設定する必要があります。 このプロパティを設定すると、 イベントが発生します DataSourceChanged

Note

プロパティ値に変更を DataSource 加える場合は、ユーザー インターフェイス (UI) スレッドで変更を行い、UI に変更が反映されるようにする必要があります。

プロパティは DataSource 、 クラスの既定の BindingSource プロパティです。

適用対象

こちらもご覧ください