Thư viện tri thức trực tuyến
Kho tài liệu với 50,000+ tài liệu học thuật
© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Tài liệu Creating and Using a DataViewManager Object pdf
Nội dung xem thử
Mô tả chi tiết
Creating and Using a DataViewManager Object
To create a DataViewManager, you use one of the following constructors:
DataViewManager()
DataViewManager(DataSet myDataSet)
where myDataSet specifies the DataSet used by the DataViewManager object. This sets
the DataSet property of the new DataViewManager object to myDataSet.
Let's take a look at an example of creating and using a DataViewManager. Assume you
have a DataSet named myDataSet, which contains a DataTable populated with rows from
the Customers table. The following example creates a DataViewManager object named
myDVM, passing myDataSet to the constructor:
DataViewManager myDVM = new DataViewManager(myDataSet);
The next example sets the Sort and RowFilter properties that will be used later when a
DataView for the Customers DataTable is created:
myDVM.DataViewSettings["Customers"].Sort = "CustomerID";
myDVM.DataViewSettings["Customers"].RowFilter = "Country = 'UK'";
Note The previous code doesn't actually create a DataView; it merely sets the properties
of any DataView created in the future that views rows from the Customers
DataTable.
The following example actually creates a DataView by calling the CreateDataView()
method of the myDVM DataViewManager, passing the customersDT DataTable to
CreateDataView():
DataView customersDV = myDVM.CreateDataView(customersDT);
The Sort and RowFilter properties of the customersDV DataView are set to CustomerID
and Country = 'UK' respectively. These are the same settings as those set earlier in the
DataViewSettings property.
Listing 13.4A shows a complete example that creates and uses the DataViewManager
shown in this section.
Listing 13.4A: USINGDATAVIEWMANAGER.CS
/*