This documentation is archived and is not being maintained.

Adding Data Views to a Form or Component

Visual Studio .NET 2003

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.

A common use for data views is to use them as data sources when data binding controls in a form. For more information, see Data Binding and Windows Forms and Data Access in Web Forms Pages.

To add a data view

  1. Create a dataset. For more information see Creating Typed Datasets with the Component Designer.
  2. Add code to populate the dataset. For more information, see Populating a DataSet from a DataAdapter.
  3. 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.

  4. 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 PropertyDescription
    (Name)The name by which you can refer to the data view in code.
    TableA 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.)
    SortAn 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.

    RowFilterAn 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.

    RowStateFilterThe 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, AllowDeleteSpecifies whether the view allows update operations (edit, new, or delete).

See Also

Introduction to Filtering and Sorting in Datasets | Filtering and Sorting Data Using Data Views | Working with Records in Data Views