By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,948 Members | 1,573 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,948 IT Pros & Developers. It's quick & easy.

Filter in datatable

P: n/a
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


Sep 9 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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/lib....dataview.aspx

hope this helps,

Cheers,
Nimesh
"Uri Dimant" wrote:
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


Sep 9 '07 #2

P: n/a
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

"Uri Dimant" <ur**@iscar.co.ilschreef in bericht
news:OS**************@TK2MSFTNGP04.phx.gbl...
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

Sep 10 '07 #3

P: n/a
Thanks Cor and Nimesh. It does work

"Cor Ligthert[MVP]" <no************@planet.nlwrote in message
news:46**********************************@microsof t.com...
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

"Uri Dimant" <ur**@iscar.co.ilschreef in bericht
news:OS**************@TK2MSFTNGP04.phx.gbl...
>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


Sep 10 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.