BindingSource.List Vlastnost

Definice

Získá seznam, ke kterému je konektor vázán.

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

Hodnota vlastnosti

Představuje IList seznam nebo null pokud k tomuto BindingSourceseznamu není přidružený žádný podkladový seznam.

Atributy

Příklady

Následující příklad kódu ukazuje Listčleny , RemoveAta Count . Pokud chcete spustit tento příklad, vložte kód do formuláře, který obsahuje pojmenovaný BindingSourceBindingSource1, dva popisky s názvem label1 a label2a tlačítko s názvem button1. Přidružte metodu button1_Click k Click události pro button1. Uživatelé jazyka Visual Basic budou muset přidat odkaz na 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

Poznámky

Třída BindingSource jednotně zpracovává různé zdroje dat. V ideálním případě by vlastnost List měla být nastavena na obecný IListparametr . Někdy však může být nutné přetypovat tuto vlastnost na konkrétnější typ. Následující tabulka ukazuje základní typ seznamu, který závisí na typu nebo hodnotě zdroje dat.

Typ zdroje dat Popis podkladového seznamu
DataSource a DataMember jsou null Prázdný ArrayListobjekt .
DataSource je null, ale DataMember není null Žádný; pokus o získání List vyvolá výjimku ArgumentException.
Instance Array An .Array
Instance IListSource Vrácená hodnota z volání GetList metody této IListSource instance.
Instance IBindingList An .IBindingList
Instance IList An .IList
Jiná instanceIList typu T A BindingList<T> s jedním prvkem.
Instance ICustomTypeDescriptor Objekt ArrayList s jedním prvkem.
IEnumerable An ArrayList s elementy zkopírovanými přes.
Typ Array položky typu DataMember "T" Úloha BindingList<T>.
AType, který představuje nebo IListSourceITypedList Instance vytvořená voláním CreateInstance(Type) metody Activator třídy . Může NotSupportedException být vyhozena.
Typ IList položky typu DataMember "T"

-nebo-

Typ bezIList typu
Úloha BindingList<T>.
Typ ICustomTypeDescriptor Žádný; pokus o získání List vyvolá výjimku NotSupportedException.

Pokud je IList načtený typ rozhraní, podkladová kolekce může být složitější, například třída nebo ArrayListDataView .

Platí pro

Viz také