BindingSource.RemoveAt(Int32) 메서드

정의

목록의 지정된 인덱스에 있는 항목을 제거합니다.

public:
 virtual void RemoveAt(int index);
public virtual void RemoveAt (int index);
abstract member RemoveAt : int -> unit
override this.RemoveAt : int -> unit
Public Overridable Sub RemoveAt (index As Integer)

매개 변수

index
Int32

제거할 항목의 인덱스(0부터 시작)입니다.

구현

예외

index가 0보다 작거나 Count 속성 값보다 큰 경우

List 속성이 나타내는 기본 목록이 읽기 전용이거나 크기가 고정되어 있는 경우

예제

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

설명

이러한 두 조건을 테스트할 수 있습니다 합니다 IsFixedSizeIsReadOnly 속성을 각각.

이 메서드는 ListChanged 이벤트입니다.

적용 대상

추가 정보