Freigeben über


BindingSource.List Eigenschaft

Definition

Ruft die Liste ab, an die der Connector gebunden ist.

public:
 property System::Collections::IList ^ List { System::Collections::IList ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Collections.IList List { get; }
[<System.ComponentModel.Browsable(false)>]
member this.List : System.Collections.IList
Public ReadOnly Property List As IList

Eigenschaftswert

Eine IList , die die Liste darstellt, oder null wenn dieser keine zugrunde liegende Liste zugeordnet BindingSourceist.

Attribute

Beispiele

Das folgende Codebeispiel veranschaulicht die ListElemente , RemoveAtund Count die Elemente. Zum Ausführen dieses Beispiels fügen Sie den Code in ein Formular ein, das eine benannte BindingSourceBindingSource1, zwei Bezeichnungen mit namen label1 und label2eine Schaltfläche mit dem Namen button1enthält. Ordnen Sie die button1_Click Methode dem Click Ereignis für button1. Visual Basic-Benutzer müssen einen Verweis auf System.Data.dllhinzufügen.

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

Hinweise

Die BindingSource Klasse behandelt unterschiedliche Datenquellen einheitlich. Idealerweise sollte die List Eigenschaft auf eine allgemeine IListEigenschaft festgelegt werden. Manchmal kann es jedoch erforderlich sein, diese Eigenschaft in einen spezifischeren Typ zu umwandeln. Die folgende Tabelle zeigt den zugrunde liegenden Listentyp, der vom Typ oder Wert der Datenquelle abhängt.

Datenquellentyp Beschreibung der zugrunde liegenden Liste
DataSource und DataMember sind null Ein leeres ArrayList.
DataSource ist null, ist aber DataMember nicht null Nichts; ein Versuch, dies List zu erhalten, löst ein ArgumentException.
Eine Array Instanz Ein Array-Element.
Eine IListSource Instanz Der Rückgabewert aus einem Aufruf der GetList Methode dieser IListSource Instanz.
Eine IBindingList Instanz Ein IBindingList-Element.
Eine IList Instanz Ein IList-Element.
Eine NichtinstanzIList vom Typ "T" A BindingList<T> mit einem Element.
Eine ICustomTypeDescriptor Instanz Ein ArrayList element mit einem Element.
Eine IEnumerable Ein ArrayList Element mit den kopierten Elementen.
Der Array Typ mit DataMember dem Elementtyp "T" Ein BindingList<T>.
A Type , das ein IListSource oder ITypedList Eine Instanz, die durch einen Aufruf der CreateInstance(Type) Methode der Activator Klasse erstellt wurde. Möglicherweise NotSupportedException wird ein Fehler ausgelöst.
Der IList Typ mit DataMember dem Elementtyp "T"

- oder -

Ein NichttypIList
Ein BindingList<T>.
Der Typ ICustomTypeDescriptor Nichts; ein Versuch, dies List zu erhalten, löst ein NotSupportedException.

Wenn der abgerufene Typ die IList Schnittstelle ist, kann die zugrunde liegende Sammlung komplexer sein, z. B. eine oder DataView eine ArrayList Klasse.

Gilt für:

Weitere Informationen