Filter and sort data in a .NET Framework Windows Forms application
Note
Datasets and related classes are legacy .NET Framework technologies from the early 2000s that enable applications to work with data in memory while the applications are disconnected from the database. They are especially useful for applications that enable users to modify data and persist the changes back to the database. Although datasets have proven to be a very successful technology, we recommend that new .NET applications use Entity Framework Core. Entity Framework provides a more natural way to work with tabular data as object models, and it has a simpler programming interface.
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 on which you want to sort; append DESC
to sort in descending order, or append ASC
to sort in ascending order.
Note
If your application does not use BindingSource components, you can filter and sort data by using DataView objects. For more information, see DataViews.
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
CompanyName
that starts with "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
CompanyName
column in descending order:
Related content
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for