BindingSource.List Własność
Definicja
Ważny
Niektóre informacje dotyczą produktów przedpremierowych, które mogą zostać znacznie zmodyfikowane przed premierą. Microsoft nie udziela żadnych gwarancji, ani wyraźnych, ani domniemanych, dotyczących informacji podanych tutaj.
Pobiera listę, z którą jest powiązany łącznik.
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
Wartość nieruchomości
Element IList reprezentujący listę lub null jeśli nie ma listy bazowej skojarzonej z tą BindingSourcelistą .
- Atrybuty
Przykłady
Poniższy przykład kodu przedstawia Listelementy członkowskie , RemoveAti Count . Aby uruchomić ten przykład, wklej kod do formularza zawierającego nazwane BindingSourceBindingSource1, dwie etykiety o nazwie i label2i przycisk o nazwie label1button1. Skojarz metodę button1_Click ze zdarzeniem Click dla button1klasy . Użytkownicy języka Visual Basic będą musieli dodać odwołanie do 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
Uwagi
Klasa BindingSource jednolicie obsługuje różne źródła danych. List Najlepiej, aby właściwość powinna być ustawiona na ogólną IListwartość . Czasami jednak może być konieczne rzutowanie tej właściwości na bardziej konkretny typ. W poniższej tabeli przedstawiono podstawowy typ listy, który zależy od typu lub wartości źródła danych.
| Typ źródła danych | Opis listy bazowej |
|---|---|
DataSource i DataMember są null |
ArrayListPusty element . |
DataSource to null, ale DataMember nie jest null |
Brak; próba uzyskania List elementu spowoduje zgłoszenie elementu ArgumentException. |
| Wystąpienie Array | Element Array. |
| Wystąpienie IListSource | Wartość zwracana z wywołania do GetList metody tego IListSource wystąpienia. |
| Wystąpienie IBindingList | Element IBindingList. |
| Wystąpienie IList | Element IList. |
| IList Wystąpienie typu "T" | Element BindingList<T> z jednym elementem. |
| Wystąpienie ICustomTypeDescriptor | Element ArrayList z jednym elementem. |
| Element IEnumerable | Element ArrayList z skopiowanymi elementami. |
| Typ Array z DataMember typem elementu "T" | Klasa BindingList<T>. |
| Element Type reprezentujący element IListSource lub ITypedList | Wystąpienie utworzone przez wywołanie CreateInstance(Type) metody Activator klasy. Może NotSupportedException zostać wyrzucony. |
| Typ IList z DataMember typem elementu "T" -lub- Typ inny niżIList |
Klasa BindingList<T>. |
| ICustomTypeDescriptor Typ | Brak; próba uzyskania List elementu spowoduje zgłoszenie elementu NotSupportedException. |
Jeśli pobrany typ jest interfejsem IList , podstawowa kolekcja może być bardziej złożona, na przykład klasa ArrayList lub DataView .