BindingSource.filter

Steve36445

Well-known member
Joined
Dec 23, 2007
Messages
58
Programming Experience
10+
Can you help me please?

I am having some success with the bindingsource.filter.

I have got the following to work-


VB.NET:
Me.SentenceBindingSource.RemoveFilter()

 Me.SentenceBindingSource.Filter = "sound_checked=false"

 Me.SentenceBindingSource.Filter = "word='drag'"

followed by

VB.NET:
 Me.SentenceTableAdapter.Fill(Me.QuestionsDataSet3.sentence)


but there still things I can+t do.

In paticular
1) How do I select records only if a certain field is empty?
2) What is the 'like' syntax?
3) How do I use wild cards?
4)Is this documented anywhere?
5)Is there anything else I should know?


Thanks,



Steve
 
Of course it's documented. Just like every type and member there's a topic dedicated to the BindingSource.Filter property in the MSDN Library. Get acquainted with the Help menu and the F1 key in your IDE.
 
re vb .net BindingSource.filter

Ref. remark from jmcilhinney.

I spent several hours searching both MSN and the internet and

could not find a suitable entry. I am sure your remarks could be

leveled at virtually any forum question.

If you know of any in formation please post it to help us all, I

thought that was the point of forums.

On a more positive note the code below summerises what I have

found so far and some links. The code seems to work. I hope

others will find it useful.


VB.NET:
Me.SentenceBindingSource.RemoveFilter()
        Me.SentenceBindingSource.Filter = "field_name is null"

        Me.SentenceBindingSource.Filter = "field_name ='1'"
        Me.SentenceBindingSource.Filter ="field_name ='1' or 

field_name2='2'"
        Me.SentenceBindingSource.Filter = "field_name ='1' and 

field_name2 ='some text'"
        Me.SentenceBindingSource.Filter = "field_name  ='1' or 

field_name2  ='2' and field_name3  ='some text'"

        fill_QuestionsDataSet3()
Other usefull info.

VB.NET:
bs.Filter = "MyColumn Is Null OR MyColumn Like '*' AND 

MyColumn NOT LIKE 'Deleted'

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=592070&SiteId=1




bs1.Filter = "id<10";
bs2.Filter = "id>=10 and id< 36";
bs3.Filter = "id>= 36";

I've not tried them


http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=278

2818&SiteId=1


"But the DataView.RowFilter does not support the '_'

wildcard. For more information, check this topic on MSDN."

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=200

8465&SiteId=1


"The filter string is written like a WHERE clause in a SQL

statement (eg. ColumnName = Value AND ColumnName2 =

Value2)"

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=592

070&SiteId=1

For SQL see-

http://www.w3schools.com/sql/sql_where.asp

I haven't answered all my questions yet but am getting there. Hope this helps others.

Steve
 
Last edited:
Then documentation for the .Net Framework library is really the first place to seek help. (after having read some books perhaps, but not everybody needs that) Press F1 key and spend some time figuring out how the help and documentation works. The whole library is quite explicitly documented. It is structured as a tree by namespace, classes, class members (methods, events, properties). All namespaces, classes and class members are described with comments, almost all of them is accompanied with code example. There are also much related articles describing special topics, usage of Visual Studio, language features etc. If you have Express and didn't install the local MSDN Express I highly recommend doing it, because using the online version is very slow to navigate. Other than browsing the documentation tree, there is the index search, but beware of Express 2008 help because it actually filters out the class library documentation, you have to filter by ".Net Framework" or "(Unfiltered)" to get this information. By highlighting keywords in code or Designer and pressin F1 key you also usually get relevant information directly. Hope this helps you understand the primary documentation for what you are operating, neither jmcilhinney or me is saying that you have to learn everything yourself and not ask questions, but we know you haven't read the "BindingSource.Filter" topic yet.
 
ref vb .net BindingSource.filter

I thnk I have read it as far as my disability alllows, partially sighted and much more, but if you can help me by giving me a specifc reference I would be greatful. I thought that was the point of forums.

Steve
 
Are you saying your disabilities prevent you from typing "BindingSource.Filter" in help index? Or that you didn't understand it? Here's online version link anyway, pay particular attention to the "The accepted syntax..." sentence and follow the link to where they say "syntax documented".
 
Thanks for your reply.

I have read the artical several times and it does not answer my question, hense the post.

My disability is irrevant in this case because I have read the article, but it does make reading large amouts of text impractical.

Steve.
 
WILDCARD CHARACTERS

Both the * and % can be used interchangeably for wildcard characters in a LIKE comparison. If the string in a LIKE clause contains a * or %, those characters should be escaped in brackets ([]). If a bracket is in the clause, the bracket characters should be escaped in brackets (for example [[] or []]). A wildcard is allowed at the start and end of a pattern, or at the end of a pattern, or at the start of a pattern. For example:

"ItemName LIKE '*product*'"

"ItemName LIKE '*product'"

"ItemName LIKE 'product*'"

Wildcard characters are not allowed in the middle of a string. For example, 'te*xt' is not allowed.
Example to filter by empty rows of a column: "name is null"

A general rule to the Filter is same syntax as the WHERE clause of Sql queries.
 
It wasn't very obvious?
MSDN said:
To form a filter value, specify the name of a column followed by an operator and a value to filter on. The filter value must be inside quotation marks, such as "LastName = 'Smith'". The accepted syntax depends on the underlying data source. If the underlying data source is a DataSet, DataTable, or DataView, you can specify Boolean expressions using the syntax documented for the DataColumn.Expression property.
I'm not sure we're working from the same definition of obvious. So as not to reprint the same long syntax description over and over it is in the one place: the topic for the DataColumn.Expression property. Every other topic for which it's relevant contains a link to that topic and none of them are hidden. I would consider that passage from MSDN quite explicit.
 
There was information there but it was't very obvious, so I missed it.

MSDN can be a bit like that. I would advocate the following:

Dont go looking for something you expect to find in the exact format you imagine it will be. You probably went to the Filter article expecting that there would be a long list of examples like what you quoted here.. you quickly scan the article and seeing nothing like what you expect, you conclude that microsoft didnt write it.

Actually, the approach is to read the Remarks section carefully, where we can se ethey direct us to the article for the .Expression property.

As another example youll find a similar thing with Formatting Strings using String.Format.. that article WONT tell you how to format a date into yyyyMMddHHmmss, for example, but it WILL point you to the .ToString article related to DateTime, where you will find your answer.

It's logical when youre used to it, you just must bear in mind that as a concice reference it doesnt arrange itself in the same way as our un-concise brains
 
Back
Top