다음을 통해 공유


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 목록을 나타내는 값이거나 nullBindingSource목록과 연결된 기본 목록이 없는 경우

특성

예제

다음 코드 예제에서는 , RemoveAtCount 멤버를 List보여 줍니다. 이 예제를 실행하려면 명명된 레이블과 두 개의 레이블 label1label2이름이 BindingSource1button1지정된 단추가 포함된 BindingSource 폼에 코드를 붙여넣습니다. 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으로 설정해야 합니다. 그러나 경우에 따라 이 속성을 보다 구체적인 형식으로 캐스팅해야 할 수 있습니다. 다음 표에서는 데이터 원본의 형식 또는 값에 따라 달라지는 기본 목록 형식을 보여 줍니다.

데이터 원본 유형 기본 목록 설명
DataSourceDataMembernull ArrayList.
DataSourcenull(이지만 DataMember 그렇지 않음) null 없음; 가져오기를 시도하면 . List 가 throw됩니다 ArgumentException.
Array 인스턴스 Array입니다.
IListSource 인스턴스 IListSource 인스턴스의 메서드에 대한 호출의 GetList 반환 값입니다.
IBindingList 인스턴스 IBindingList입니다.
IList 인스턴스 IList입니다.
"T" 형식의 인스턴스가 아닌IList 경우 하나의 요소가 있는 A BindingList<T> 입니다.
ICustomTypeDescriptor 인스턴스 ArrayList 하나의 요소가 있는 항목입니다.
An IEnumerable ArrayList 요소가 복사된 항목입니다.
항목 형식이 Array "T"인 형식 DataMember 입니다. BindingList<T>.
Type IListSource 또는ITypedList 클래스의 메서드를 호출하여 CreateInstance(Type) 만든 인스턴스입니다 Activator . A가 NotSupportedException throw될 수 있습니다.
항목 형식이 IList "T"인 형식 DataMember 입니다.

-또는-

형식이IList 아닌
BindingList<T>.
ICustomTypeDescriptor 형식 없음; 가져오기를 시도하면 . List 가 throw됩니다 NotSupportedException.

검색된 형식이 인터페이스인 IList 경우 내부 컬렉션이 더 복잡할 수 있습니다(예: 클래스 ArrayList ) DataView .

적용 대상

추가 정보