Compartir por


BindingSource.List Propiedad

Definición

Obtiene la lista a la que está enlazado 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

que IList 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 , dos etiquetas denominadas BindingSource1label1 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 objeto 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 Un objeto vacío ArrayList.
DataSource es null, pero DataMember no es null Ninguno; un intento de obtener el List producirá una ArgumentExceptionexcepción .
Una Array instancia Un Array.
Una IListSource instancia Valor devuelto de una llamada al GetList método de esta IListSource instancia.
Una IBindingList instancia Un IBindingList.
Una IList instancia Un IList.
Una instancia que noIList es de tipo "T" un BindingList<T> elemento con un elemento .
Una ICustomTypeDescriptor instancia con ArrayList un elemento .
Un IEnumerable con ArrayList los elementos copiados.
Tipo Array con DataMember tipo de elemento "T" Un 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 . Se puede producir una NotSupportedException excepción .
Tipo IList con DataMember tipo de elemento "T"

O bien

Un tipo que noIList es
Un objeto BindingList<T>.
El tipo ICustomTypeDescriptor Ninguno; un intento de obtener el List 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