BindingSource.List Propiedad

Definición

Obtiene la lista a la que está enlazada el conector.

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

Valor de propiedad

IList que representa la lista, o null si no hay ninguna lista subyacente asociada a este BindingSource.

Atributos

Ejemplos

En el ejemplo de código siguiente se muestran los Listmiembros , RemoveAty Count . Para ejecutar este ejemplo, pegue el código en un formulario que contenga un BindingSource denominado BindingSource1, dos etiquetas denominadas label1 y label2, y un botón denominado button1. Asocie el button1_Click método al Click evento para button1. Los usuarios de Visual Basic deberán agregar una referencia a 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

Comentarios

La BindingSource clase controla uniformemente distintos orígenes de datos. Idealmente, la List propiedad debe establecerse en un valor general IList. Sin embargo, a veces puede ser necesario convertir esta propiedad en un tipo más específico. En la tabla siguiente se muestra el tipo de lista subyacente, que depende del tipo o valor del origen de datos.

Tipo de origen de datos Descripción de la lista subyacente
DataSource y DataMember son null Objeto ArrayList vacío.
DataSource es null, pero DataMember no es null Ninguno; un intento de obtención List de producirá una ArgumentExceptionexcepción .
Una Array instancia Una clase Array.
Una IListSource instancia Valor devuelto de una llamada al GetList método de esta IListSource instancia.
Una IBindingList instancia Una clase IBindingList.
Una IList instancia Una clase IList.
Una instancia que noIList es de tipo "T" con BindingList<T> un elemento .
Una ICustomTypeDescriptor instancia con ArrayList un elemento .
IEnumerable. con ArrayList los elementos copiados.
Tipo Array con DataMember del tipo de elemento "T" Objeto BindingList<T>.
que Type representa un IListSource objeto o ITypedList Instancia creada por una llamada al CreateInstance(Type) método de la Activator clase . NotSupportedException Se puede producir una excepción .
Tipo IList con DataMember del tipo de elemento "T"

o bien

Un tipo que noIList es
Objeto BindingList<T>.
El tipo ICustomTypeDescriptor Ninguno; un intento de obtención List de producirá una NotSupportedExceptionexcepción .

Si el tipo recuperado es la IList interfaz, la colección subyacente puede ser más compleja, como una ArrayList clase o DataView .

Se aplica a

Consulte también