BindingSource.DataSource プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > BindingSource.DataSource プロパティの意味・解説 

BindingSource.DataSource プロパティ

メモ : このプロパティは、.NET Framework version 2.0 で新しく追加されたものです。

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

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Dim instance As BindingSource
Dim value As Object

value = instance.DataSource

instance.DataSource = value
public Object DataSource { get; set;
 }
/** @property */
public Object get_DataSource ()

/** @property */
public void set_DataSource (Object value)

プロパティ値
データ ソースとして機能する Object。既定値は null 参照 (Visual Basic では Nothing) です。

解説解説

DataSource プロパティには、複数のデータ ソース (型、オブジェクト、型のリストなど) を設定できます。設定されたデータ ソースは、リストとして公開されます。次の表は、共通のデータ ソースの一部と、評価の結果、作成されるリストの対応を示したものです。

DataSource プロパティ

作成されるリスト

null 参照 (Visual Basic では Nothing)

オブジェクトの空の IBindingList。項目を追加すると、リストが、追加された項目の型に設定されます。

null 参照 (Visual Basic では Nothing) (ただし DataMember が設定されている場合)

サポートされていません。ArgumentException が発生します。

リスト以外の型または "T" 型のオブジェクト

"T" 型の空の IBindingList。

配列のインスタンス

配列の要素を含む IBindingList。

IEnumerable のインスタンス

IEnumerable の項目を含む IBindingList。

"T" 型を含むリストのインスタンス

"T" 型を含む IBindingList のインスタンス。

また、DataSource は、IListSource や ITypedList など他のリスト型にも設定できます。BindingSource がこれらの型を適切に処理します。この場合、リストに含まれる型に既定のコンストラクタがあることを確認する必要があります。

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

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

使用例使用例

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

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
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;
}
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;
   
   // Handle the ListChanged event.
   this->customersBindingSource->ListChanged +=
      gcnew ListChangedEventHandler(
         this, &Form1::customersBindingSource_ListChanged
 );
   
   // Attach the BindingSource to the DataGridView.
   this->customersDataGridView->DataSource =
      this->customersBindingSource;
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
BindingSource クラス
BindingSource メンバ
System.Windows.Forms 名前空間
BindingSource.DataMember プロパティ
IList
IListSource



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「BindingSource.DataSource プロパティ」の関連用語

BindingSource.DataSource プロパティのお隣キーワード

   

英語⇒日本語
日本語⇒英語
   



BindingSource.DataSource プロパティのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS