DataViewManager: Multiple Tables and Filter

A

Alex Pecoraro

Hi all,

We have a situation where we are using an DataSet object to store/load a file (e.g. there is no database), and have the need to be able to bind a subset of the dataset to a grid control.

The problem is that we need to be able to filter across two of the tables to determine which data to display. A DataViewManager of the DataSet that contains the two tables and DataRelation seems to be exactly what we want. The microsoft documentation says:
Data View Manager: A data view manager is particularly useful when you are working with related tables and want to sort or filter child records from a master table. As an example, imagine a dataset containing a Customers table, an Orders table, and a DataRelation object that links the two tables. You can use individual data views to sort the Customers table by CompanyName and the Orders table by OrderDate. However, when you use individual data views to sort this way - for example, when you use the relation object's GetChildRecords method to get Orders records - the records won't be sorted. In contrast, if you use a data view manager, they will be.
And gives an example of how to sort by criteria across two tables and their relationship. I want to use the DataViewManager to do Filtering.

Here's the basic code that depicts what we're trying to do:
// ds is my DataSet which contains Table1 and Table2 along w/ a DataRelation between them
DataViewManager dvm = ds.DefaultViewManager;
dvm.DataViewSettings["Table1"].RowFilter = "<filter 1 goes here>"
dvm.DataViewSettings["Table2"].RowFilter = "<filter 2 goes here>";

m_Grid.DataSource = dvm;
m_Grid.DataMember = "Table1";
If we only use a filter on the single table we're binding to it works. We've tested the filters individually and we're sure they are working.

Any tricks to getting this to work? Any suggested work arounds? Any help is much appreciated.

TIA,
Alex
 
A

Alex Pecoraro

Finally found an article that helps with complex ADO.NET queries...

http://support.microsoft.com/?id=321896

Hi all,

We have a situation where we are using an DataSet object to store/load a file (e.g. there is no database), and have the need to be able to bind a subset of the dataset to a grid control.

The problem is that we need to be able to filter across two of the tables to determine which data to display. A DataViewManager of the DataSet that contains the two tables and DataRelation seems to be exactly what we want. The microsoft documentation says:
Data View Manager: A data view manager is particularly useful when you are working with related tables and want to sort or filter child records from a master table. As an example, imagine a dataset containing a Customers table, an Orders table, and a DataRelation object that links the two tables. You can use individual data views to sort the Customers table by CompanyName and the Orders table by OrderDate. However, when you use individual data views to sort this way - for example, when you use the relation object's GetChildRecords method to get Orders records - the records won't be sorted. In contrast, if you use a data view manager, they will be.
And gives an example of how to sort by criteria across two tables and their relationship. I want to use the DataViewManager to do Filtering.

Here's the basic code that depicts what we're trying to do:
// ds is my DataSet which contains Table1 and Table2 along w/ a DataRelation between them
DataViewManager dvm = ds.DefaultViewManager;
dvm.DataViewSettings["Table1"].RowFilter = "<filter 1 goes here>"
dvm.DataViewSettings["Table2"].RowFilter = "<filter 2 goes here>";

m_Grid.DataSource = dvm;
m_Grid.DataMember = "Table1";
If we only use a filter on the single table we're binding to it works. We've tested the filters individually and we're sure they are working.

Any tricks to getting this to work? Any suggested work arounds? Any help is much appreciated.

TIA,
Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top