다음을 통해 공유


BindingSource.Count 속성

정의

현재 Filter 값을 고려하여 기본 목록의 총 항목 수를 가져옵니다.

public:
 virtual property int Count { int get(); };
[System.ComponentModel.Browsable(false)]
public virtual int Count { get; }
[<System.ComponentModel.Browsable(false)>]
member this.Count : int
Public Overridable ReadOnly Property Count As Integer

속성 값

기본 목록의 필터링된 총 항목 수입니다.

구현

특성

예제

다음 코드 예제에서는 , 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

설명

속성은 Count 속성 값에 의해 수정된 대로 속성이 List 나타내는 기본 목록의 Filter 항목 수를 가져옵니다.

적용 대상

추가 정보