Filter or Sort Data with a DataView

Problem

You want to show a subset of data from a DataTable or sort that data.

Solution

Set a filter or sort rows using the DataView.RowFilter and DataView.Sort properties.

Discussion

When you bind a DataTable to a Windows control, you’re actually making use of another type of object that acts as a mediator: the DataView. The DataView exposes the information from the DataTable and allows you to filter rows or apply a sort order.

You can create a DataView for a DataTable and bind the DataView to a control. However, it’s more common to bind controls directly to a DataTable. In this case, the DataView referenced by the DataTable.DefaultView property is used automatically. Thus, if you want to configure sorting or filtering, ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.