Assembly : System.Windows.Forms (dans system.windows.forms.dll)
SyntaxePublic ReadOnly Property List As IList
Dim instance As BindingSource Dim value As IList value = instance.List
public IList List { get; }
public: property IList^ List { IList^ get (); }
/** @property */
public IList get_List ()
public function get List () : IList
Valeur de la propriété
IList qui représente la liste, ou référence Null (Nothing en Visual Basic) s'il n'y a aucune liste sous-jacente associée à ce BindingSource.
NotesLa classe BindingSource gère uniformément différentes sources de données. Dans l'idéal, la propriété List doit avoir pour valeur un IList général. Toutefois, il peut s'avérer quelquefois nécessaire d'effectuer un cast de cette propriété vers un type plus spécifique. Le tableau suivant affiche le type de liste sous-jacent qui dépend du type ou de la valeur de la source de données.
| Type de source de données | Description de liste sous-jacente |
|---|---|
| DataSource et DataMember sont référence Null (Nothing en Visual Basic) | ArrayList vide. |
| DataSource est référence Null (Nothing en Visual Basic), mais DataMember n'est pas référence Null (Nothing en Visual Basic). | Aucun ; la tentative d'obtention de List lèvera ArgumentException. |
| Instance de Array. | Array. |
| Instance de IListSource. | Valeur de retour d'un appel à la méthode GetList de cette instance de IListSource. |
| Instance de IBindingList. | IBindingList. |
| Instance de IList. | IList. |
| Instance n'appartenant pas à IList de type "T". | BindingList avec un élément. |
| Instance de ICustomTypeDescriptor. | ArrayList avec un élément. |
| ArrayList sur lequel les éléments sont copiés. | |
| Type Array avec DataMember d'élément de type "T". | BindingList. |
| Type qui représente IListSource ou ITypedList. | Une instance créée par un appel à la méthode CreateInstance de la classe Activator. Une NotSupportedException peut être levée. |
| Type IList avec DataMember d'élément de type "T". - ou - Type n'appartenant pas à IList. | BindingList. |
| Type ICustomTypeDescriptor. | Aucun ; la tentative d'obtention de List lèvera NotSupportedException. |
Si le type récupéré est l'interface IList, la collection sous-jacente peut être plus complexe, telle qu'une classe ArrayList ou DataView.
ExempleL'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 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 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() End Sub End Class
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(); }
Plates-formesWindows 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.
Informations de version
Outils (masquer)
S'enregistrer
Liste des Membres
Qui est en ligne?
FAQ