This documentation is archived and is not being maintained.

Creating and Working with Data View Managers

Visual Studio .NET 2003

A data view manager is an object that contains a collection of data views, one for each table in a dataset. The data view manager provides centralized access to sorted and filtered data. This is especially helpful when working with related tables. For an overview, see Introduction to Filtering and Sorting in Datasets.

Note   You must create and configure data view managers in code; there is no design-time object for a data view manager.

To create and configure a data view manager

  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. Create an instance of the DataViewManager class.
  4. Set the data view manager's DataSet property to the dataset you created in Step 1.
  5. Set sort and filter expressions by accessing individual tables through the DataViewSettings collection.
    Note   Accessing a table using the DataViewSettings property causes the data view manager to dynamically create a data view for that table. (The data view does not exist until you access it.)
  6. If you want to bind controls to the data view manager, set their data-binding properties after configuring the data view manager. For example, in a Windows Form, you can set a control's DataSource property to the data view manager and its DataMember property to the name of the table (and thus, data view) to bind to.

The following example shows how to create a data view manager and set sort and filter information. The example assumes that there is a dataset called dsCustomersOrders with a Customers and an Orders table. After creating the data view manager, the example binds a data grid to the Titles table available via the data view manager.

' Visual Basic
Dim dvm As New DataViewManager()
dvm.DataSet = dsCustomersOrders1
dvm.DataViewSettings("Customers").Sort = "CompanyName"
dvm.DataViewSettings("Orders").Sort = "OrderDate"
Datagrid1.DataSource = dvm
Datagrid1.DataMember = "titles"

// C#
DataViewManager dvm = new DataViewManager();
dvm.DataSet = dsCustomersOrders1;
dvm.DataViewSettings["Customers"].Sort = "CompanyName";
dvm.DataViewSettings["Orders"].Sort = "OrderDate";
dataGrid1.DataSource = dvm;
dataGrid1.DataMember = "titles";

See Also

Introduction to Filtering and Sorting in Datasets | Filtering and Sorting Data Using Data Views | Data Binding and Windows Forms | Data Access in Web Forms Pages