DataView Class

Represents a databindable, customized view of a DataTable for sorting, filtering, searching, editing, and navigation.

Namespace: System.Data
Assembly: System.Data (in system.data.dll)

public ref class DataView : public MarshalByValueComponent, IBindingListView, IBindingList, IList, 
	ICollection, IEnumerable, ITypedList, ISupportInitializeNotification, ISupportInitialize
public class DataView extends MarshalByValueComponent implements IBindingListView, IBindingList, 
	IList, ICollection, IEnumerable, ITypedList, ISupportInitializeNotification, 
	ISupportInitialize
public class DataView extends MarshalByValueComponent implements IBindingListView, IBindingList, 
	IList, ICollection, IEnumerable, ITypedList, ISupportInitializeNotification, 
	ISupportInitialize
Not applicable.

A major function of the DataView is to allow for data binding on both Windows Forms and Web Forms.

Additionally, a DataView can be customized to present a subset of data from the DataTable. This capability lets you have two controls bound to the same DataTable, but that show different versions of the data. For example, one control might be bound to a DataView that shows all the rows in the table, and a second might be configured to display only the rows that have been deleted from the DataTable. The DataTable also has a DefaultView property. This returns the default DataView for the table. For example, if you want to create a custom view on the table, set the RowFilter on the DataView returned by the DefaultView.

To create a filtered and sorted view of data, set the RowFilter and Sort properties. Then, use the Item property to return a single DataRowView.

You can also add and delete from the set of rows using the AddNew and Delete methods. When you use those methods, the RowStateFilter property can set to specify that only deleted rows or new rows be displayed by the DataView.

NoteNote:

If you do not explicitly specify sort criteria for DataView, the DataRowView objects in DataView are sorted based on the index of DataView's corresponding DataRow in the DataTable.RowsDataRowCollection.

LINQ to DataSet allows developers to create complex, powerful queries over a DataSet by using LINQ. A LINQ to DataSet query returns an enumeration of DataRow objects, however, which is not easily used in a binding scenario. DataView can be created from a LINQ to DataSet query and takes on the filtering and sorting characteristics of that query. LINQ to DataSet extends the functionality of the DataView by providing LINQ expression-based filtering and sorting, which allows for much more complex and powerful filtering and sorting operations than string-based filtering and sorting. See Data Binding and LINQ to DataSet for more information.

The following example creates a single DataTable with one column and five rows. Two DataView objects are created and the RowStateFilter is set on each to show different views of the table data. The values are then printed.

No code example is currently available or this language may not be supported.

The following example creates a DataView of online orders ordered by total due from a LINQ to DataSet query:

This type is safe for multithreaded read operations. You must synchronize any write operations.

Windows 98, Windows Server 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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show: