BindingSource.Filter Tulajdonság
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Lekéri vagy beállítja a megtekintett sorok szűréséhez használt kifejezést.
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
Tulajdonság értéke
Egy sztring, amely meghatározza a sorok szűrésének módját. Az alapértelmezett érték a null.
Megvalósítás
- Attribútumok
Példák
Az alábbi példa bemutatja, hogyan használhatja a Filter tulajdonságot egy DataView. A példa futtatásához illessze be a kódot egy Windows űrlapba, és hívja meg PopulateDataViewAndFilter az űrlap konstruktorából vagy Load eseménykezelési módszerből. Az űrlapnak importálnia kell a névtereket és System.Xml a System.IO névtereket.
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
Megjegyzések
Az összetett adatkötési forgatókönyvekben Filter általában használt tulajdonság lehetővé teszi a részhalmaz DataSourcemegtekintését. Csak az interfészt implementáló mögöttes listák támogatják a IBindingListView szűrést.
Ha Filter nem null, akkor a BindingSource tulajdonság átkerül az alapul szolgáló listára. Ha ezt a tulajdonságot az objektum inicializálása során állítja be, a rendszer elhalasztja a hívást, amíg az inicializálás befejeződik.
Szűrőérték létrehozásához adja meg egy oszlop nevét, amelyet egy operátor és egy szűrni kívánt érték követ. Az elfogadott szűrőszintaxis az alapul szolgáló adatforrástól függ. Ha a mögöttes adatforrás egy DataSet, DataTablevagy DataView, megadhatja a logikai kifejezéseket a tulajdonsághoz DataColumn.Expression dokumentált szintaxis használatával.
A tulajdonság értéke Filter befolyásolja a tulajdonság értékét Count . Emellett az Filter érték megmarad, amikor az adatforrás megváltozik. A szűrés DataSourceleállításához hívja meg a metódust RemoveFilter .