Ce sujet n'a pas encore été évalué - Évaluez ce sujet

BindingSource.RemoveAt, méthode

Remarque : cette méthode est nouvelle dans le .NET Framework version 2.0.

Supprime l'élément au niveau de l'index spécifié dans la liste.

Espace de noms : System.Windows.Forms
Assembly : System.Windows.Forms (dans system.windows.forms.dll)

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

Paramètres

index

Index de base zéro de l'élément à supprimer.

Type d'exceptionCondition

ArgumentOutOfRangeException

index est inférieur à zéro ou supérieur à la valeur de la propriété Count.

NotSupportedException

La liste sous-jacente représentée par la propriété List est en lecture seule ou a une taille fixe.

Ces deux conditions peuvent être testées par les propriétés IsFixedSize et IsReadOnly, respectivement.

Cette méthode déclenche l'événement ListChanged.

L'exemple de code suivant illustre les membres List, RemoveAt et Count. Pour exécuter cet exemple, collez le code dans un formulaire qui contient un BindingSource nommé BindingSource1, deux étiquettes nommées label1 et label2 et un bouton nommé button1. Associez la méthode button1_Click à l'événement Click de button1. Les utilisateurs de Visual Basic devront ajouter une référence à 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 pour Pocket PC, Windows Mobile pour Smartphone, Windows Server 2003, Windows XP Édition Media Center, Windows XP Professionnel Édition x64, Windows XP SP2, Windows XP Starter Edition

Le .NET Framework ne prend pas en charge toutes les versions de chaque plate-forme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise.

.NET Framework

Prise en charge dans : 2.0

.NET Compact Framework

Prise en charge dans : 2.0
Cela vous a-t-il été utile ?
(1500 caractères restants)

Ajouts de la communauté

AJOUTER
© 2013 Microsoft. Tous droits réservés.