Trouble appling filter to datatable.defaultview

  • Thread starter Thread starter moondaddy
  • Start date Start date
M

moondaddy

Using vb.net 2.0 I'm trying to filter a dataview. From the code examples
I've seen, it looks correct, but its not having any effect. The datatable
has about 250 rows of data. after I apply the filter and set the dataview
as the datasource, I still see all of the rows. However, when I step
through it I can see the 'RowStateFilter' property says 'CurrentRows {22}'
which tells me the new filter returned 22 rows. If this is true, then why
doesn't the datagrid show only 22 rows?

Here's my code:


Dim sSort As String
Dim sFilter As String = "Co_ShortName Like '*" & _newText & "*' OR
Co_LongName Like '*" & _newText & "*'"

If Me.ugGoTo.DataSource Is Nothing Then Return
_newText = tx.Text

Static isDesc As Boolean
If isDesc = True Then
sSort = "Co_ShortName DESC"
Else
sSort = "Co_ShortName ASC"
End If
_tbCompanyNames.DefaultView.RowFilter = ""
_tbCompanyNames.DefaultView.RowFilter = sFilter
_tbCompanyNames.DefaultView.Sort = sSort
ugGoTo.DataSource = Nothing
ugGoTo.DataSource = _tbCompanyNames.DefaultView



Thanks.
 
There could be a few different things causing this... but first, let's make
sure it's the RowFilter.

You mention the RowStateFilter but remember, that's != RowFilter. So, if
you use DataTable.DefaultView.Count... what number does that give you?
Before going further down the path I just want to isolate this b/c if it's
correct, then it's probably just a problem that can be solved by calling
DoEvents or refreshing the control
 
Thanks. I found the problem and it was something else I did, but the code I
posted actually works. Sorry for the trouble.

W.G. Ryan said:
There could be a few different things causing this... but first, let's
make sure it's the RowFilter.

You mention the RowStateFilter but remember, that's != RowFilter. So, if
you use DataTable.DefaultView.Count... what number does that give you?
Before going further down the path I just want to isolate this b/c if it's
correct, then it's probably just a problem that can be solved by calling
DoEvents or refreshing the control
 
Back
Top