Filter and sort data in a Windows Forms application
This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, use the version selector at the top left. We recommend upgrading to Visual Studio 2019. Download it here
You filter data by setting the Filter property to a string expression that returns the desired records.
You sort data by setting the Sort property to the column name you want to sort on; append
DESC to sort in descending order, or append
ASC to sort in ascending order.
To filter data by using a BindingSource component
Set the Filter property to the expression you want to return. For example, the following code returns customers with a
CompanyNamethat starts with "B":
customersBindingSource.Filter = "CompanyName like 'B'";
CustomersBindingSource.Filter = "CompanyName like 'B'"
To sort data by using a BindingSource component
Set the Sort property to the column you want to sort on. For example, the following code sorts customers on the
CompanyNamecolumn in descending order:
customersBindingSource.Sort = "CompanyName Desc";
CustomersBindingSource.Sort = "CompanyName Desc"