다음을 통해 공유


BindingSource.Filter 속성

정의

표시되는 행을 필터링하는 데 사용되는 식을 가져오거나 설정합니다.

public:
 virtual property System::String ^ Filter { System::String ^ get(); void set(System::String ^ value); };
public virtual string Filter { get; set; }
public virtual string? Filter { get; [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members of types used in the filter expression might be trimmed.")] set; }
public virtual string Filter { get; [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members of types used in the filter expression might be trimmed.")] set; }
member this.Filter : string with get, set
[<set: System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members of types used in the filter expression might be trimmed.")>]
member this.Filter : string with get, set
Public Overridable Property Filter As String

속성 값

행을 필터링하는 방법을 지정하는 문자열입니다. 기본값은 null입니다.

구현

특성

예제

다음 예제에서는 속성과 함께 사용 Filter 하는 방법을 보여 있습니다 DataView. 이 예제를 실행하려면 코드를 Windows Form에 붙여넣고 양식의 생성자 또는 Load 이벤트 처리 메서드에서 호출 PopulateDataViewAndFilter 합니다. 양식에서 네임스페이스와 네임스페이 System.XmlSystem.IO 스를 가져와야 합니다.

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&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&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

설명

일반적으로 복잡한 데이터 바인딩 시나리오 Filter 에서 사용되는 이 속성을 사용하면 .의 DataSource하위 집합을 볼 수 있습니다. 인터페이스를 구현 IBindingListView 하는 기본 목록만 필터링을 지원합니다.

그렇지 않은 null경우 FilterBindingSource 속성을 기본 목록으로 전달합니다. 개체를 초기화하는 동안 이 속성을 설정하면 초기화가 완료될 때까지 호출이 지연됩니다.

필터 값을 구성하려면 열 이름 뒤에 연산자와 필터링할 값을 지정합니다. 허용되는 필터 구문은 기본 데이터 원본에 따라 달라집니다. 기본 데이터 원본이 DataSet또는 DataTableDataView속성에 대해 문서화된 DataColumn.Expression 구문을 사용하여 부울 식을 지정할 수 있습니다.

속성 값은 Filter 속성 값에 영향을 줍니다 Count . 또한 데이터 원본이 Filter 변경될 때 값이 유지됩니다. 필터링을 DataSource중지하려면 메서드를 호출합니다 RemoveFilter .

적용 대상

추가 정보