BindingSource Filter and Find ?

Jess31
Jess31 used Ask the Experts™
on
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?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Miguel OzSenior Software Engineer
Top Expert 2009

Commented:
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

Commented:
Hi

If you want your filter to work you want this:

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

Commented:
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);
OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

Miguel OzSenior Software Engineer
Top Expert 2009

Commented:
Please specify if you are binding using the property designer or manually.

Author

Commented:
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?

Commented:
If it find nothind it returns -1 - and this is valid postion for setting bs.Position = as it points to "No Current record".

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial