System.Data.DataView Class

Represents a databindable, customized view of a System.Data.DataTable for sorting, filtering, searching, editing, and navigation. The System.Data.DataView does not store data, but instead represents a connected view of its corresponding System.Data.DataTable. Changes to the System.Data.DataView’s data will affect the System.Data.DataTable. Changes to the System.Data.DataTable’s data will affect all System.Data.DataViews associated with it.

See Also: DataView Members

Syntax

[System.ComponentModel.Designer("Microsoft.VSDesigner.Data.VS.DataViewDesigner, Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.ComponentModel.Design.IDesigner")]
[System.ComponentModel.DefaultProperty("Table")]
[System.ComponentModel.DefaultEvent("PositionChanged")]
[System.ComponentModel.Editor("Microsoft.VSDesigner.Data.Design.DataSourceEditor, Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public class DataView : System.ComponentModel.MarshalByValueComponent, System.ComponentModel.IBindingListView, System.ComponentModel.ISupportInitializeNotification, System.ComponentModel.ITypedList

Remarks

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

Additionally, a System.Data.DataView can be customized to present a subset of data from the System.Data.DataTable. This capability lets you have two controls bound to the same System.Data.DataTable, but that show different versions of the data. For example, one control might be bound to a System.Data.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 System.Data.DataTable. The System.Data.DataTable also has a DataTable.DefaultView property. This returns the default System.Data.DataView for the table. For example, if you want to create a custom view on the table, set the DataView.RowFilter on the System.Data.DataView returned by the DataTable.DefaultView.

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

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

Note:

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.Rows DataRowCollection.

linq_dataset allows developers to create complex, powerful queries over a System.Data.DataSet by using vbteclinq. A linq_dataset query returns an enumeration of System.Data.DataRow objects, however, which is not easily used in a binding scenario. System.Data.DataView can be created from a linq_dataset query and takes on the filtering and sorting characteristics of that query. linq_dataset extends the functionality of the System.Data.DataView by providing vbteclinq 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.

Requirements

Namespace: System.Data
Assembly: System.Data (in System.Data.dll)
Assembly Versions: 1.0.3300.0, 1.0.5000.0, 2.0.0.0