BindingSource.Filter プロパティ
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

行のフィルタ処理方法を指定する文字列。既定値は null 参照 (Visual Basic では Nothing) です。

Filter プロパティは、通常、複合データ バインディングで使用され、DataSource の一部を表示できるようにします。基底のリストがフィルタ処理をサポートするのは、IBindingListView インターフェイスを実装している場合のみです。
Filter が null 参照 (Visual Basic では Nothing) でない場合、BindingSource はこのプロパティを基底のリストに渡します。このプロパティをオブジェクトの初期化中に設定すると、初期化が完了するまで呼び出しが保留されます。
フィルタの値を作成するには、列名の後に演算子およびフィルタ処理する値を付けて指定します。フィルタの値は、引用符で囲んで "LastName = 'Smith'" のようにする必要があります。
Filter プロパティの値は、データ ソースが変更されても保持されます。DataSource のフィルタ処理を中止するには、RemoveFilter メソッドを呼び出します。

Filter プロパティと Sort プロパティのコード例を次に示します。この例を実行するには、BindingSource1 という名前の BindingSource と、dataGridView1 という名前の DataGridView を含むフォームにコードを貼り付けます。次に、フォームの読み込みイベントを処理し、読み込みイベント処理メソッドで InitializeSortedFilteredBindingSource を呼び出します。Visual Basic を使用する場合、System.Data.dll への参照を追加する必要があります。
Private Sub InitializeSortedFilteredBindingSource() ' 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 the adapter with the contents of the customer table. customersTableAdapter.Fill(customerTable) ' Set data source for BindingSource1. BindingSource1.DataSource = customerTable ' Filter the items to show contacts who are owners. BindingSource1.Filter = "ContactTitle='Owner'" ' Sort the items on the company name in descending order. BindingSource1.Sort = "Country DESC, Address ASC" ' Set the data source for dataGridView1 to BindingSource1. dataGridView1.DataSource = BindingSource1 End Sub
private void InitializeSortedFilteredBindingSource() { // 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 the adapter with the contents of the customer table. customersTableAdapter.Fill(customerTable); // Set data source for BindingSource1. BindingSource1.DataSource = customerTable; // Filter the items to show contacts who are owners. BindingSource1.Filter = "ContactTitle='Owner'"; // Sort the items on the company name in descending order. BindingSource1.Sort = "Country DESC, Address ASC"; // Set the data source for dataGridView1 to BindingSource1. dataGridView1.DataSource = BindingSource1; }

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からBindingSource.Filter プロパティを検索する場合は、下記のリンクをクリックしてください。

- BindingSource.Filter プロパティのページへのリンク