BindingSource.List プロパティ

定義

コネクタのバインド先であるリストを取得します。

public:
 property System::Collections::IList ^ List { System::Collections::IList ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Collections.IList List { get; }
[<System.ComponentModel.Browsable(false)>]
member this.List : System.Collections.IList
Public ReadOnly Property List As IList

プロパティ値

リストを表す IList。この BindingSource に関連付けられている基底のリストがない場合は null

属性

次のコード例は、および Count メンバーをListRemoveAt示しています。 この例を実行するには、 という名前の 、および という名前の 2 つのラベルlabel2label1、および という名前BindingSource1のボタンbutton1を含むBindingSourceフォームにコードを貼り付けます。 メソッドを の button1_Click イベントbutton1Click関連付けます。 Visual Basic ユーザーは、System.Data.dllへの参照を追加する必要があります。

private void button1_Click(object sender, EventArgs e)
{
    // Create the connection string, data adapter and data table.
    SqlConnection connectionString =
         new SqlConnection("Initial Catalog=Northwind;" +
         "Data Source=localhost;Integrated Security=SSPI;");
    SqlDataAdapter customersTableAdapter =
        new SqlDataAdapter("Select * from Customers", connectionString);
    DataTable customerTable = new DataTable();

    // Fill the adapter with the contents of the customer table.
    customersTableAdapter.Fill(customerTable);

    // Set data source for BindingSource1.
    BindingSource1.DataSource = customerTable;

    // Set the label text to the number of items in the collection before
    // an item is removed.
    label1.Text = "Starting count: " + BindingSource1.Count.ToString();

    // Access the List property and remove an item.
    BindingSource1.List.RemoveAt(4);

    // Remove an item directly from the BindingSource. 
    // This is equivalent to the previous line of code.
    BindingSource1.RemoveAt(4);

    // Show the new count.
    label2.Text = "Count after removal: " + BindingSource1.Count.ToString();
}
    Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) _
        Handles button1.Click

        ' Create the connection string, data adapter and data table.
        Dim connectionString As New SqlConnection("Initial Catalog=Northwind;" & _
            "Data Source=localhost;Integrated Security=SSPI;")
        Dim customersTableAdapter As New SqlDataAdapter("Select * from Customers", _
            connectionString)
        Dim customerTable As New DataTable()

        ' Fill the adapter with the contents of the customer table.
        customersTableAdapter.Fill(customerTable)

        ' Set data source for BindingSource1.
        BindingSource1.DataSource = customerTable

        ' Set the label text to the number of items in the collection before
        ' an item is removed.
        label1.Text = "Starting count: " + BindingSource1.Count.ToString()

        ' Access the List property and remove an item.
        BindingSource1.List.RemoveAt(4)

        ' Remove an item directly from the BindingSource. 
        ' This is equivalent to the previous line of code.
        BindingSource1.RemoveAt(4)

        ' Show the new count.
        label2.Text = "Count after removal: " + BindingSource1.Count.ToString()

    End Sub
End Class

注釈

クラスは BindingSource 、さまざまなデータ ソースを一様に処理します。 理想的には、 プロパティを List 一般的 IListな に設定する必要があります。 ただし、このプロパティをより具体的な型にキャストする必要がある場合があります。 次の表は、基になるリストの種類を示しています。これは、データ ソースの型または値によって異なります。

[データ ソースの種類] 基になるリストの説明
DataSourceDataMember はです null 空の ArrayList
DataSourcenullですが、 DataMember はではありません null なし;を取得 List しようとすると、 ArgumentExceptionがスローされます。
Arrayインスタンス Array
IListSourceインスタンス このIListSourceインスタンスの メソッドのGetList呼び出しからの戻り値。
IBindingListインスタンス IBindingList
IListインスタンス IList
型 "T" の非IList インスタンス BindingList<T> 1 つの要素を持つ 。
ICustomTypeDescriptorインスタンス ArrayList 1 つの要素を持つ 。
IEnumerable ArrayList要素がコピーされた 。
Array項目の種類DataMemberが "T" の型 BindingList<T>
Typeまたは を表す 。IListSourceITypedList クラスの メソッドの CreateInstance(Type) 呼び出しによって作成された Activator インスタンス。 が NotSupportedException スローされる場合があります。
IList項目の種類DataMemberが "T" の型

- または -

IList
BindingList<T>
ICustomTypeDescriptor なし;を取得 List しようとすると、 NotSupportedExceptionがスローされます。

取得した型が インターフェイスのIList場合、基になるコレクションは、 クラスや DataView クラスなどArrayList、より複雑になる可能性があります。

適用対象

こちらもご覧ください