BindingSource.Filter BindingSource.Filter BindingSource.Filter BindingSource.Filter Property

Definición

Obtiene o establece la expresión utilizada para filtrar las filas que se deben mostrar.Gets or sets the expression used to filter which rows are viewed.

public:
 virtual property System::String ^ Filter { System::String ^ get(); void set(System::String ^ value); };
public virtual string Filter { get; set; }
member this.Filter : string with get, set
Public Overridable Property Filter As String

Valor de propiedad

Cadena que especifica cómo se van a filtrar las filas.A string that specifies how rows are to be filtered. De manera predeterminada, es null.The default is null.

Implementaciones

Ejemplos

El ejemplo siguiente muestra cómo usar el Filter propiedad con un DataView.The following example shows how to use the Filter property with a DataView. Para ejecutar este ejemplo, pegue el código en un formulario de Windows y la llamada PopulateDataViewAndFilter desde el constructor del formulario o Load el método de control de eventos.To run this example, paste the code into a Windows Form and call PopulateDataViewAndFilter from the form's constructor or Load event-handling method. El formulario debe importar el System.Xml y System.IO espacios de nombres.Your form should import the System.Xml and System.IO namespaces.

private void PopulateDataViewAndFilter()
{
    DataSet set1 = new DataSet();

    // Some xml data to populate the DataSet with.
    string musicXml =
        "<?xml version='1.0' encoding='UTF-8'?>" +
        "<music>" +
        "<recording><artist>Coldplay</artist><cd>X&amp;Y</cd></recording>" +
        "<recording><artist>Dave Matthews</artist><cd>Under the Table and Dreaming</cd></recording>" +
        "<recording><artist>Dave Matthews</artist><cd>Live at Red Rocks</cd></recording>" +
        "<recording><artist>Natalie Merchant</artist><cd>Tigerlily</cd></recording>" +
        "<recording><artist>U2</artist><cd>How to Dismantle an Atomic Bomb</cd></recording>" +
        "</music>";

    // Read the xml.
    StringReader reader = new StringReader(musicXml);
    set1.ReadXml(reader);

    // Get a DataView of the table contained in the dataset.
    DataTableCollection tables = set1.Tables;
    DataView view1 = new DataView(tables[0]);

    // Create a DataGridView control and add it to the form.
    DataGridView datagridview1 = new DataGridView();
    datagridview1.AutoGenerateColumns = true;
    this.Controls.Add(datagridview1);

    // Create a BindingSource and set its DataSource property to
    // the DataView.
    BindingSource source1 = new BindingSource();
    source1.DataSource = view1;

    // Set the data source for the DataGridView.
    datagridview1.DataSource = source1;

    //The Filter string can include Boolean expressions.
    source1.Filter = "artist = 'Dave Matthews' OR cd = 'Tigerlily'";
}
Private Sub PopulateDataViewAndFilter() 
    Dim set1 As New DataSet()
    
    ' Some xml data to populate the DataSet with.
    Dim musicXml As String = "<?xml version='1.0' encoding='UTF-8'?>" & _
        "<music>" & _
        "<recording><artist>Coldplay</artist><cd>X&amp;Y</cd></recording>" & _
        "<recording><artist>Dave Matthews</artist><cd>Under the Table and Dreaming</cd></recording>" & _
        "<recording><artist>Dave Matthews</artist><cd>Live at Red Rocks</cd></recording>" & _
        "<recording><artist>Natalie Merchant</artist><cd>Tigerlily</cd></recording>" & _
        "<recording><artist>U2</artist><cd>How to Dismantle an Atomic Bomb</cd></recording>" & _
        "</music>"
    
    ' Read the xml.
    Dim reader As New StringReader(musicXml)
    set1.ReadXml(reader)
    
    ' Get a DataView of the table contained in the dataset.
    Dim tables As DataTableCollection = set1.Tables
    Dim view1 As New DataView(tables(0))
    
    ' Create a DataGridView control and add it to the form.
    Dim datagridview1 As New DataGridView()
    datagridview1.AutoGenerateColumns = True
    Me.Controls.Add(datagridview1)
    
    ' Create a BindingSource and set its DataSource property to
    ' the DataView.
    Dim source1 As New BindingSource()
    source1.DataSource = view1
    
    ' Set the data source for the DataGridView.
    datagridview1.DataSource = source1
    
    ' The Filter string can include Boolean expressions.
    source1.Filter = "artist = 'Dave Matthews' OR cd = 'Tigerlily'"

End Sub

Comentarios

Se utiliza normalmente en escenarios de enlace de datos complejos, el Filter propiedad le permite ver un subconjunto de la DataSource.Typically used in complex data-binding scenarios, the Filter property allows you to view a subset of the DataSource. Solo subyacente enumera que implementan el IBindingListView admiten el filtrado de la interfaz.Only underlying lists that implement the IBindingListView interface support filtering.

Cuando Filter no null, el BindingSource pasa esta propiedad a la lista subyacente.When Filter is not null, the BindingSource passes this property to the underlying list. Si establece esta propiedad durante la inicialización del objeto, la llamada se aplazará hasta que una vez completada la inicialización.If you set this property during object initialization, the call will be deferred until after initialization is complete.

Para formar un valor de filtro, especifique el nombre de una columna seguido de un operador y un valor para el filtro.To form a filter value, specify the name of a column followed by an operator and a value to filter on. La sintaxis de filtro aceptada depende del origen de datos subyacente.The accepted filter syntax depends on the underlying data source. Si el origen de datos subyacente es un DataSet, DataTable, o DataView, puede especificar expresiones booleanas utilizando la sintaxis documentada para el DataColumn.Expression propiedad.If the underlying data source is a DataSet, DataTable, or DataView, you can specify Boolean expressions using the syntax documented for the DataColumn.Expression property.

El valor de la Filter propiedad afecta al valor de la Count propiedad.The value of the Filter property affects the value of the Count property. Además, el Filter valor se conservará cuando cambian los datos originales.Additionally, the Filter value will persist when the data source changes. Para detener el filtrado del DataSource, llame a la RemoveFilter método.To stop filtering the DataSource, call the RemoveFilter method.

Se aplica a

Consulte también: