Name

DataView

Synopsis

The DataView represents a custom view of a DataTable that can be bound to controls. It allows you to apply row sorting and filtering without affecting the underlying data. All DataTable binding takes place through a DataView. When you bind to a DataTable object, you are actually binding to the DataTable.DefaultView, which is an automatically created DataView object. You can configure this DataView or create a new DataView. In fact, you can even create multiple DataView objects for the same DataTable and use them to display different views of the same data in different user interface controls.

Some significant properties of the DataView are Sort, RowFilter, and RowStateFilter. Sort is a SQL expression that sets column-based sorting (as in CustomerID ASC). RowFilter is a SQL expression that works like a WHERE clause, including only rows that match certain criteria (such as CustomerID > 100). Finally, RowStateFilter shows only rows that have a specified DataViewRowState. For more information about the DataView objects and the syntax you can use to filter and sort data within them, refer to Chapter 28. Much as with a Data-Table, you can add new rows (using AddNew( )) and select existing ones (using Find( )) through a DataView.

public class DataView : System.ComponentModel.MarshalByValueComponent, 

System.ComponentModel.IBindingList, IList, ICollection, IEnumerable, System.ComponentModel.ITypedList, 

System.ComponentModel.ISupportInitialize {

// Public Constructors

Get ADO.NET in a Nutshell now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.