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입니다.

특성

예제

다음 코드 예제는 List, RemoveAt, 및 Count 멤버입니다. 이 예제를 실행 하려면 코드를 포함 하는 폼에 붙여 넣습니다를 BindingSource 라는 BindingSource1, 라는 두 개의 레이블은 label1 하 고 label2, 라는 단추 button1. 연결 된 button1_Click 메서드를 Click 이벤트에 대 한 button1합니다. 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입니다.
DataSource 됩니다 null, 하지만 DataMember 아닙니다 null 해당 항목이 없습니다. 가져오려는 시도가 합니다 List 시킵니다는 ArgumentException합니다.
Array 인스턴스 Array입니다.
IListSource 인스턴스 에 대 한 호출의 반환 값을 GetList 이 메서드의 IListSource 인스턴스.
IBindingList 인스턴스 IBindingList입니다.
IList 인스턴스 IList입니다.
비-IList "T" 형식은의 인스턴스 BindingList<T> 하나의 요소를 사용 하 여 합니다.
ICustomTypeDescriptor 인스턴스 ArrayList 하나의 요소를 사용 하 여 합니다.
IEnumerable입니다. ArrayList 복사한 요소를 사용 하 여 합니다.
합니다 Array 유형과 DataMember 항목의 "T"를 입력 합니다. BindingList<T>
A Type 나타내는 IListSource 또는 ITypedList 호출 하 여 만든 인스턴스를 CreateInstance(Type) 메서드는 Activator 클래스. NotSupportedException throw 될 수 있습니다.
합니다 IList 유형과 DataMember 항목의 "T"를 입력 합니다.

또는

비-IList 형식
BindingList<T>
ICustomTypeDescriptor 형식 해당 항목이 없습니다. 가져오려는 시도가 합니다 List 시킵니다는 NotSupportedException합니다.

형식을 검색 하는 경우는 IList 인터페이스를 기본 컬렉션에서와 같이 더 복잡할 수 있습니다는 ArrayList 또는 DataView 클래스입니다.

적용 대상

추가 정보