Binding to two dataviews

G

Guest

Hi,

Why is it that if I have two seperate instances of a DataView & use the
defaultView of a table to set them, then filter each one by Rowstate in
different ways for each, they are both set the same, to the last rowstate
filter applied to one of them?

I can get around this by using the constructor of the Dataview & passing in
a table reference but I'm curious as to what two seperate Dataviews reference
when using the default view?

Thanks for any ideas on this
Ant
 
M

Miha Markic [MVP C#]

Hi,

If I understand properly you are referencing the DataTable.DefaultView
twice - you are not using two instances.
If you want a new instance then create a new DataView()...
 
G

Guest

Hi Miha, thanks again.

In fact I created two seperate instances of the DataView: Below:

// Instantiate two seperate DV's with same default view

DataView dvChanges = new DataView();
DataView dvAdded = new DataView();

// Filter & bind to one grid with first dv
dvChanges = dsMaster.Products.DefaultView;
dvChanges.RowStateFilter = DataViewRowState.ModifiedCurrent;
dgChanges.DataSource = dvChanges;
dgChanges.Refresh();


// Filter & bind to other grid with second dv
dvAdded = dsMaster.Products.DefaultView;


// This line causes problem
dvAdded.RowStateFilter = DataViewRowState.Added;
dgAdded.DataSource = dvAdded;
dgAdded.Refresh();

// All is ok until I filter the second dataview. This seems to filter the
first data view as well. Why? They are two seperate instances of the
Dataview, sharing the same dataView. Is the Default view a copy or a
reference? is the default view being filtered?

Thanks for your ideas.
Ant






Miha Markic said:
Hi,

If I understand properly you are referencing the DataTable.DefaultView
twice - you are not using two instances.
If you want a new instance then create a new DataView()...

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Ant said:
Hi,

Why is it that if I have two seperate instances of a DataView & use the
defaultView of a table to set them, then filter each one by Rowstate in
different ways for each, they are both set the same, to the last rowstate
filter applied to one of them?

I can get around this by using the constructor of the Dataview & passing
in
a table reference but I'm curious as to what two seperate Dataviews
reference
when using the default view?

Thanks for any ideas on this
Ant
 
M

Miha Markic [MVP C#]

Hi Ant,

There is your problem. The correct way would be:
DataView dvChanges = new DataView(dsMaster.Products);
DataView dvAdded = new DataView(dsMaster.Products);

And then get rid of
dvChanges = dsMaster.Products.DefaultView;
and
dvAdded = dsMaster.Products.DefaultView;

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Ant said:
Hi Miha, thanks again.

In fact I created two seperate instances of the DataView: Below:

// Instantiate two seperate DV's with same default view

DataView dvChanges = new DataView();
DataView dvAdded = new DataView();

// Filter & bind to one grid with first dv
dvChanges = dsMaster.Products.DefaultView;
dvChanges.RowStateFilter = DataViewRowState.ModifiedCurrent;
dgChanges.DataSource = dvChanges;
dgChanges.Refresh();


// Filter & bind to other grid with second dv
dvAdded = dsMaster.Products.DefaultView;


// This line causes problem
dvAdded.RowStateFilter = DataViewRowState.Added;
dgAdded.DataSource = dvAdded;
dgAdded.Refresh();

// All is ok until I filter the second dataview. This seems to filter the
first data view as well. Why? They are two seperate instances of the
Dataview, sharing the same dataView. Is the Default view a copy or a
reference? is the default view being filtered?

Thanks for your ideas.
Ant






Miha Markic said:
Hi,

If I understand properly you are referencing the DataTable.DefaultView
twice - you are not using two instances.
If you want a new instance then create a new DataView()...

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Ant said:
Hi,

Why is it that if I have two seperate instances of a DataView & use
the
defaultView of a table to set them, then filter each one by Rowstate in
different ways for each, they are both set the same, to the last
rowstate
filter applied to one of them?

I can get around this by using the constructor of the Dataview &
passing
in
a table reference but I'm curious as to what two seperate Dataviews
reference
when using the default view?

Thanks for any ideas on this
Ant
 

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