Multiple DataViews on the same DataTable appear to interact

R

Ron L

I have a DataTable that is being maintained in a Model class. I also have a
View class which creates a DataView from the DataTable that the Model passes
it. The view class then has methods to filter the contents of the DataView
so that the user can narrow down the list to the items they are interested
in. This all works fine as long as I only have a single instance of the
View class, however whenever I create a second instance of the view class
and have it make its DataView use the same DataTable I find that any filter
applied to the DataView in one window is also applied to the DataView in the
other form. Can anyone explain this to me? It seems that as long as I am
using 2 independant DataViews (dim dv as new DataView(model.GetTable()) they
shouldn't interact.

TIA
Ron L
 
G

Guest

Ron,
The problem is that all the views are connected to the same table. To avoid
this, when creating additional views, create the main table from your Model
class and use separate copy of this table for each view:

dim t2 as Datatable = tMain.Copy
dim dv2 = t2.DefaultView
DataGrid2.DataSource = dv2

This way each view is connected to a different table and filtering one will
not affect the others.

Hope that helps,
Daniel
 
R

Ron L

Some further, amplifying information, the interaction we are seeing is with
datagrids on each form, each bound to its own dataview.

TIA
Ron L
 
R

Ron L

Daniel

Thanks for the response. The problem with keeping multiple copies is that
the tables can be updated, and I want to be able to perform the update in
one place. I suppose, if I have to, I can keep track of the copies in a
central location and perform the update on all of them whenever it happens.
I was hoping that I wouldn't need to add that complexity.

Ron L
 
G

Guest

Ron,

Maybe you can work around this by refreshing the datasource views for each
datagrid everytime the user updates the main database. You don't need to keep
track of the multiple copies, just create the new copy, and pass its default
dataview to the datagrid as datasource each time the user updates the
database.
I am not sure if that will fit your needs, but I used it to solve a similiar
problem and it worked fine.

Daniel
 

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