Link to home
Start Free TrialLog in
Avatar of Jess31
Jess31

asked on

BindingSource Filter and Find ?

I have a Bindingsource, bound to a DataTable, and has a filter set (BS.Filter="DayOfWeek=5"). When I do a BS.Find it seems that is is searching (and returning) also rows that that outside the filter. Is this the way .Find works or am I doing something wrong? If this is the way .Find is meant to work is there another way of searching that will adhear to the Filter?
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

Try:
BS.Filter="DayOfWeek =' 5'".
You are missing the single quote. Check:
http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource.filter.aspx
Hi

If you want your filter to work you want this:

MyBindingSource.Filter = "State = 'NY' OR State = 'MA' OR State = 'CO'";
Avatar of uldis
uldis

Could you please post a code snippet? BS Find searches ar based on PropertyDescriptor not just column name.
Like:

PropertyDescriptorCollection pdc = bs.CurrencyManager.GetItemProperties();
bs.Position = bs.Find(pdc["my_column_name], my_searchable_value);
Please specify if you are binding using the property designer or manually.
Avatar of Jess31

ASKER

I'm not missing a single quote, this is a numeric column.

I using code to filter, here is the code:

BSCustomerPossibleRoutes.Filter = "DayOfWeek=" & CType(DaysDates.DayOfWeek(DateTimePicker2.Value), String)
 BSCustomerPossibleRoutes.ResetBindings(False)

here the BS is setup:
BSCustomerPossibleRoutes = New BindingSource
BSCustomerPossibleRoutes.DataSource = DSCustomerPossibleRoutes
BSCustomerPossibleRoutes.DataMember = "CustomerPossibleRoute"

question/problem:

when doing
bs.position = bs.find
is it searching only the filtered set or the whole set, and what does it return if it finds nothing?

ASKER CERTIFIED SOLUTION
Avatar of uldis
uldis

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial