Filter in datatable

U

Uri Dimant

Hello
We use VS 2005.
I fill a data table with simple data from database (one table) which has one
column called 'flag' filtering by numbers as 1,2,3.
Now that I have all data in data table I'd like to filter it by value in
'flag' column. I have three datagrid views on my form and would like to
fill each grid with filtered data. I mean
Sub FillDataGrid (dt as datatable)

with Grid1
dt.DefaultView.RowFilter = "(TestTypeID = " & cmbTestTypes.SelectedValue & "
AND flag=1 )"

DataBindings.Clear()

..DataSource = dt.DefaultView

end with

with Grid2
dt.DefaultView.RowFilter = "(TestTypeID = " & cmbTestTypes.SelectedValue & "
AND flag=2)"

DataBindings.Clear()

..DataSource = dt.DefaultView

end with

end sub

My question is why I get for all grids the last filtered data table . I the
above case I get the data filered by FLAG=2 for Grid1 as well?

How to solve the problem?

Thank you
 
G

Guest

Hi,
since you are using the same datatable to bind the data to both the grids,
as soon as you change the row filter, all the grids that are bound to the
datatable will refresh the data, so you will see the same data in both the
grids.

you can solve this problem by declaring multiple dataview objects and
setting the filters on these views instead of the data tables default view.
bind the data grids to the data views thus created, instead of binding to the
dataset.
http://msdn2.microsoft.com/en-us/library/system.data.dataview.aspx

hope this helps,

Cheers,
Nimesh
 
C

Cor Ligthert[MVP]

Hi Uri,

To say Nimesh answer in other words, create at least two extra 'New'
dataviews.

Give them all including the default their own filter and you will see that
you have 3 different grids.

Cor
 
U

Uri Dimant

Thanks Cor and Nimesh. It does work

Cor Ligthert said:
Hi Uri,

To say Nimesh answer in other words, create at least two extra 'New'
dataviews.

Give them all including the default their own filter and you will see that
you have 3 different grids.

Cor
 

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