Sdílet prostřednictvím


BindingSource.List Vlastnost

Definice

Získá seznam, ke kterému je spojnice vázána.

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 neexistuje žádný podkladový seznam přidružený k tomuto BindingSource.

Atributy

Příklady

Následující příklad kódu ukazuje List, RemoveAta Count členové. Pokud chcete tento příklad spustit, vložte kód do formuláře, který obsahuje pojmenovaný BindingSourceBindingSource1, dva popisky pojmenované label1 a label2a tlačítko s názvem button1. Přidružte metodu button1_ClickClick k 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ě List by vlastnost měla být nastavena na obecný IList. Někdy však může být nutné přetypovat tuto vlastnost na konkrétnější typ. Následující tabulka uvádí 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ý ArrayList.
DataSource je null, ale DataMember není null Žádný; pokus o získání List ho vyhodí .ArgumentException
Instance Array Nějaký Array.
Instance IListSource Návratová hodnota z volání GetList metody této IListSource instance.
Instance IBindingList Nějaký IBindingList.
Instance IList Nějaký IList.
IList Jiná než instance typu T A BindingList<T> s jedním prvkem.
Instance ICustomTypeDescriptor A ArrayList s jedním prvkem.
An IEnumerable Prvek ArrayList s prvky zkopírovanými přes.
Typ Array s typem DataMember položky "T" Nějaké BindingList<T>.
A Type představující nebo IListSourceITypedList Instance vytvořená voláním CreateInstance(Type) metody Activator třídy. Možná NotSupportedException je to vyhozeno.
Typ IList s typem DataMember položky "T"

nebo

Jiný typ nežIList typ
Nějaké BindingList<T>.
Typ ICustomTypeDescriptor Žádný; pokus o získání List ho vyhodí .NotSupportedException

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

Platí pro

Viz také