Multiple Data Views to sort and filter data in a dataset?

G

Guest

I was under the impression that you could use data views to have multiple
sorts and filters on a dataset or data table. I want to bind two different
combo boxes to different data views for a single table. I set the row filter
for the first data view and bind the view to the combo box, I then set the
row filter for the second view and bind it to the second combo box. Both
combo boxes display the last row filter applied to the data set even though
they were bound to different views? I think I am missing something.

ToDV = addresses_DS.Tables["Customer_Address_MSTR"].DefaultView;
ToDV.RowFilter = "TypeID = 'To'";
ToDV.Sort = "NameID";

toName.DataBindings.Clear();
toName.DataSource = ToDV;
toName.DisplayMember = "NameID";
toName.ValueMember = "NameID";
toName.SelectedItem = null;

FromDV = addresses_DS.Tables["Customer_Address_MSTR"].DefaultView;
FromDV.RowFilter = "TypeID = 'From'";
FromDV.Sort = "NameID";

fromName.DataBindings.Clear();
fromName.DataSource = FromDV;
fromName.DisplayMember = "NameID";
fromName.ValueMember = "NameID";
fromName.SelectedItem = null;
 
M

Mark Broadbent

On both your ToDV and FromDV you are repointing your reference to a table.
You simply need to set the DataView's Table property to the relevant table.

e.g. this is a snippet of some of my code where i use a dataview to show a
user all changes they have made via datagrid1.

this.oleDbDataAdapter1.Fill(dataSet11);
this.dataGrid1.DataSource = dataSet11.Tables[0];
this.dataView1.Table = dataSet11.Tables[0];
this.dataView1.RowStateFilter =
System.Data.DataViewRowState.ModifiedOriginal;
this.dataGrid2.DataSource = dataView1;

br,

Mark.
 
G

Guest

I get It, I was creating two pointers/references to the table default view,
not creating copies of the default view that would maintain their own
properties.

Adjusting the code to this, is what I really wanted to do and works perfect.
ToDV = new DataView();
ToDV.Table = addresses_DS.Tables["Customer_Address_MSTR"];

Thanks Mark,
--
T.Kitt


Mark Broadbent said:
On both your ToDV and FromDV you are repointing your reference to a table.
You simply need to set the DataView's Table property to the relevant table.

e.g. this is a snippet of some of my code where i use a dataview to show a
user all changes they have made via datagrid1.

this.oleDbDataAdapter1.Fill(dataSet11);
this.dataGrid1.DataSource = dataSet11.Tables[0];
this.dataView1.Table = dataSet11.Tables[0];
this.dataView1.RowStateFilter =
System.Data.DataViewRowState.ModifiedOriginal;
this.dataGrid2.DataSource = dataView1;

br,

Mark.


Troy said:
I was under the impression that you could use data views to have multiple
sorts and filters on a dataset or data table. I want to bind two
different
combo boxes to different data views for a single table. I set the row
filter
for the first data view and bind the view to the combo box, I then set the
row filter for the second view and bind it to the second combo box. Both
combo boxes display the last row filter applied to the data set even
though
they were bound to different views? I think I am missing something.

ToDV = addresses_DS.Tables["Customer_Address_MSTR"].DefaultView;
ToDV.RowFilter = "TypeID = 'To'";
ToDV.Sort = "NameID";

toName.DataBindings.Clear();
toName.DataSource = ToDV;
toName.DisplayMember = "NameID";
toName.ValueMember = "NameID";
toName.SelectedItem = null;

FromDV = addresses_DS.Tables["Customer_Address_MSTR"].DefaultView;
FromDV.RowFilter = "TypeID = 'From'";
FromDV.Sort = "NameID";

fromName.DataBindings.Clear();
fromName.DataSource = FromDV;
fromName.DisplayMember = "NameID";
fromName.ValueMember = "NameID";
fromName.SelectedItem = null;
 
Top