Re: DefaultView.RowFilter by RobinS
RobinS
Thu Jan 25 18:15:40 CST 2007
Here's a post I just posted for someone over in
microsoft.public.languages.vb.data that explains how
to use the BindingSource to do filtering. This is version 2005;
I don't think it was available in 2003.
------------------------------------
You can create the BindingSource in code, although I
would just add one to the form and name it, then set the
properties in code. It's in the Data components. Either way,
it should work.
You bind your controls to the BindingSource, and the
BindingSource to the Data Source.
Then you can use all of the features of the Binding Source,
like Filter, Sort, etc. Any change you make to the binding source
is immediately displayed on the screen. So even if you changed
your data source, the screen updates w/o any other effort on your
part. And you can filter and sort w/o impacting the original
data source.
When you load your form:
'load myDataSet.Tables("myTable")
'set up the binding source
Dim myBindingSource As BindingSource = New BindingSource()
myBindingSource.DataSource = myDataSet.Tables("myTable")
'set up the bindings for the listview
myListView.DataSource = myBindingSource
'set whatever properties the ListView needs in order to bind it,
' using the BindingSource instead of the dataset
When you want to filter your listview:
myBindingSource.Filter = "EmployeeName = 'LazyGuy'"
It's like magic!
Robin S.
--------------------------------------------------
"RobinS" <RobinS@NoSpam.yah.none> wrote in message
news:E6udnd4odJY-2iTYnZ2dnUVZ_oupnZ2d@comcast.com...
> Are you filtering it for display on a form, like based on some
> criteria on the form? Is it databound?
>
> Are you using VB2005?
>
> If so, you can use a BindingSource in between your data and your
> bound controls, and apply the filter to that instead of to your
> datatable. I think that will be faster.
>
> Robin S.
> -----------------------
> "Joe" <jbassking@noemail.noemail> wrote in message
> news:eCAKvoKQHHA.420@TK2MSFTNGP06.phx.gbl...
>> Hello all,
>>
>> I'm having a performance problem using the
>> DataTable.DefaultView.RowFilter. When setting the filter to MyField =
>> "Something" this takes about 12 seconds (this isn't the issue). Next
>> if I change the filter to MyField In ('SomethingElse') it takes about
>> 1 second (still not the issue), Next I set the filter to "". This
>> takes about 5 seconds (still not the issue). Finally if I set the
>> filter back to MyField = "Something" or MyField In ('SomethingElse')
>> it takes like 30-45 seconds. This is the issue.
>>
>> My DataTable is bound to a single control but I remove the binding
>> prior to changing the RowFilter and it doesn't make a difference.
>>
>> In a test app the 1st filter takes 12 seconds, the 2nd filter takes
>> 468 ms, no filter takes 6 seconds and back to the 1st takes 453 ms.
>>
>> I cannot find a way to debug what it's doing in my actual app. I
>> tried stepping into RowFilter = "....." but nothing happens (thought
>> maybe there was an event I subscribed to and forgot) and as far as I
>> can tell there are no other controls bound to this DataTable.
>>
>> Are there any tricks out there that may help me narrow this down?
>>
>> Thanks for any help,
>> Joe
>>
>
>