Adding Data Views to a Form or Component
A data view is an object that acts as a layer on top of the data table, providing a filtered and sorted view of the table's contents. (You can also use a data view manager, which acts like a collection of data views.) For more information, see Introduction to Filtering and Sorting in Datasets. You can use design-time tools to add a data view to a form or component.
To add a data view
- Create a dataset. For more information see Creating Typed Datasets with the Component Designer.
- Add code to populate the dataset. For more information, see Populating a DataSet from a DataAdapter.
- From the Data tab of the Toolbox, drag a DataView item onto the form or component.
A new data view with the default name DataView1 is added to form or component.
- If you want to configure the data view at design time (rather than in code at run time), select the data view and use the Properties window to configure the data view. The following table lists commonly used properties of the data view.
Note You can set all of these properties at run time except the name.
DataView Property Description (Name) The name by which you can refer to the data view in code. Table A reference to the table (DataTable object) that this is a data view for. You can select a table name from the drop-down list. You must set this property or the view will not contain any records. (However, you can set it at run time.) Sort An expression indicating how to order the records represented by the view. (The data table itself is not sorted.) The most typical expression includes the name of a column in the table and, optionally, the qualifier ASC or DESC to indicate the sort direction. However, you can sort by the results of any expression, including calculations.
For more information about syntax for sort expressions, see DataColumn.Expression Property.
RowFilter An expression specifying which records to include in the view. The expression is evaluated as a Boolean expression; if the expression returns true, the record is included in the view. An example expression might look like the following:
Price > 10.00
For more information about syntax for filter expressions, see DataColumn.Expression Property.
RowStateFilter The version of a record to include in the view. The default is CurrentRows, which gets a version of the row that includes any changes made to it.
For more information about the versions of records in a data table, see Introduction to Dataset Updates
AllowEdit, AllowNew, AllowDelete Specifies whether the view allows update operations (edit, new, or delete).