Questo argomento non è stato ancora valutato - Valuta questo argomento

Metodo BindingSource.RemoveAt

Nota: questo metodo è stato introdotto con .NET Framework versione 2.0.

Rimuove l'elemento presente nell'elenco in corrispondenza dell'indice specificato.

Spazio dei nomi: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public virtual void RemoveAt (
	int index
)
public void RemoveAt (
	int index
)
public function RemoveAt (
	index : int
)

Parametri

index

Indice in base zero dell'elemento da rimuovere.

Tipo di eccezioneCondizione

ArgumentOutOfRangeException

index è minore di zero o maggiore del valore della proprietà Count.

NotSupportedException

L'elenco sottostante rappresentato dalla proprietà List è in sola lettura o ha una dimensione fissa.

È possibile verificare queste due condizioni utilizzando rispettivamente le proprietà IsFixedSize e IsReadOnly.

Questo metodo genera l'evento ListChanged.

Nell'esempio di codice riportato di seguito vengono illustrati i membri List, RemoveAt e Count. Per eseguire l'esempio, incollare il codice in un form contenente un oggetto BindingSource denominato BindingSource1, due etichette denominate label1 e label2 e un pulsante denominato button1. Associare il metodo button1_Click all'evento Click per button1. Gli utenti di Visual Basic devono aggiungere un riferimento a 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 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.RemoveAt(4);

    // Show the new count.
    label2.Text = "Count after removal: " + BindingSource1.Count.ToString();
}

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile per Pocket PC, Windows Mobile per Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework non supporta tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema.

.NET Framework

Supportato in: 2.0

.NET Compact Framework

Supportato in: 2.0
Il documento è risultato utile?
(1500 caratteri rimanenti)

Aggiunte alla community

AGGIUNGI
© 2013 Microsoft. Tutti i diritti riservati.