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 나타내는 기본 목록이 읽기 전용이거나 크기가 고정되어 있습니다.

예제

다음 코드 예제에서는 , ListRemoveAt 멤버를 Count보여 줍니다. 이 예제를 실행하려면 명명된 레이블과 두 개의 레이블 BindingSourceBindingSource1이름이 label1label2지정된 단추가 포함된 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

설명

이러한 두 조건은 각각 및 IsFixedSize 속성을 사용하여 IsReadOnly 테스트할 수 있습니다.

이 메서드는 이벤트를 발생 줍니다 ListChanged .

적용 대상

추가 정보