Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > multiple filter binding source
 

multiple filter binding source

I tried to the following code to filter a column ('ProjectStatus' Column) in a datagridview

Me.ProjectBindingSource.Filter = "(ProjectStatus like '" & filter(0) & ") And (ProjectStatus like '" & filter(1) & ") and (ProjectStatus like '" & filter(2) ")"

I am getting errors with this. Is this the best way to filter the if so what am I doing wrong?

Thanks

Randy0128  Tuesday, September 08, 2009 12:30 AM
Hi,

Sorry may be my word confused you. What I mean is you can first bind the data queried from database to the DataGridView without filter. Do you see all data there? Then call the BindingSource.Filter to get the filtered rows. It works properly on my side, I hope you can find the problem soon.

Sincerely,
Kira Qian
Please mark the replies as answers if they help and unmark if they don't.
  • Marked As Answer byRandy0128 Thursday, September 10, 2009 12:44 PM
  •  
Kira Qian  Thursday, September 10, 2009 2:15 AM
Hello Randy,

What error message did you get? You'd better code like this
Dim filterString As String = "(ProjectStatus like '" & filter(0) & ") And (ProjectStatus like '" & filter(1) & ") and (ProjectStatus like '" & filter(2) ")"
Me.ProjectBindingSource.Filter = filterString

Put a break point at first line of code, bedug your application to see if the filterString is what you want.

Please inform me the test result.

Sincerely,
Kira Qian
Please mark the replies as answers if they help and unmark if they don't.
Kira Qian  Wednesday, September 09, 2009 3:34 AM
Thanks for your help.

I put in the your code "Dim filterString As String = "(ProjectStatus like '" & filter(0) & ") And (ProjectStatus like '" & filter(1) & ") and (ProjectStatus like '" & filter(2) ")" and I got an "end of statement error", so I change it to this

Dim

filterString As String = "(ProjectStatus like '" & filter(0) & ") And (ProjectStatus like '" & filter(1) & ") and (ProjectStatus like '" & filter(2) & ")"

When I ran it I got this for filterstring:

filterString = "(ProjectStatus like 'Bid) And (ProjectStatus like 'Awarded) and (ProjectStatus like 'Not Awarded)"

Now I get this error on the 'Me.ProjectBindingSource.Filter = filterString' line

'Syntax error: Missing operand after 'Awarded' operator.'

any idea what can be causing this error?
Randy0128  Wednesday, September 09, 2009 5:30 AM
Hello Randy,

I guess it should be
filterString = "(ProjectStatus like 'Bid' ) And (ProjectStatus like 'Awarded' ) and (ProjectStatus like 'Not Awarded' )"
So you have missed the last ' for a pair.

Please try to change a little as below.
filterString As String = "(ProjectStatus like '" & filter(0) & "' ) And (ProjectStatus like '" & filter(1) & "' ) and (ProjectStatus like '" & filter(2) & "' )"

Please tell me the result.

Sincerely,
Kira Qian
Please mark the replies as answers if they help and unmark if they don't.
Kira Qian  Wednesday, September 09, 2009 5:37 AM
I had already tried that and I don't get an error, but there are no content in my DGV. This is what the filterstring is:

filterString = "(ProjectStatus like 'Bid' ) And (ProjectStatus like 'Awarded' ) and (ProjectStatus like 'Not Awarded' )"
Randy0128  Wednesday, September 09, 2009 5:54 AM
Hello,

It seems there is no record match the filter condition "(ProjectStatus like 'Bid' ) And (ProjectStatus like 'Awarded' ) and (ProjectStatus like 'Not Awarded' )", please try another condition, or you can find a special record from the datasource and make the filter condition accordingly. I think the logical is correct, the only problem is the data. Once you have enough data, you can test it.

Sincerely,
Kira Qian
Please mark the replies as answers if they help and unmark if they don't.
Kira Qian  Wednesday, September 09, 2009 6:01 AM
I do have records that contain each one of the filter criteria. If for example I use this

Me

.ProjectBindingSource.Filter = "ProjectStatus like '" & filter(0) & "%'"

The correct records are placed in the DGV.

Randy0128  Wednesday, September 09, 2009 6:08 AM
Hello,

Sorry I forgot to say that "%" is necessary for the match string since you are using like in this case.

Please try the following string.
filterString As String = "(ProjectStatus like '%" & filter(0) & "%' ) And (ProjectStatus like '%" & filter(1) & "%' ) and (ProjectStatus like '%" & filter(2) & "%' )"

Sincerely,
Kira Qian
Please mark the replies as answers if they help and unmark if they don't.
Kira Qian  Wednesday, September 09, 2009 6:13 AM
I tried that earlier and I also tried with the '%' at the end of each search criterie and got the same result. No records in my datagridview.;

filterString = "(ProjectStatus like '%Bid%' ) And (ProjectStatus like '%Awarded%' ) and (ProjectStatus like '%Not Awarded%' )"

Any other Ideas?
Randy0128  Wednesday, September 09, 2009 6:19 AM
Hello,

Do you have records in your datasource?

Sincerely,
Kira Qian
Please mark the replies as answers if they help and unmark if they don't.
Kira Qian  Wednesday, September 09, 2009 6:25 AM



I'm not sure what you me. All the records are contain in a table that is load when the form is called

Me

.ProjectTableAdapter.Fill(Me.BuildersEstimatorDatabaseDataSet.Project)

Randy0128  Wednesday, September 09, 2009 6:31 AM
Hi,

Sorry may be my word confused you. What I mean is you can first bind the data queried from database to the DataGridView without filter. Do you see all data there? Then call the BindingSource.Filter to get the filtered rows. It works properly on my side, I hope you can find the problem soon.

Sincerely,
Kira Qian
Please mark the replies as answers if they help and unmark if they don't.
  • Marked As Answer byRandy0128 Thursday, September 10, 2009 12:44 PM
  •  
Kira Qian  Thursday, September 10, 2009 2:15 AM
Thanks for your help. I think that might have been the problem, but I changed my options to only filter by one criteria at a time instead of multiple criterias.
Randy0128  Thursday, September 10, 2009 12:46 PM

You can use google to search for other answers

Custom Search

More Threads

• DataGridView: Double-line header
• DataGridViewComboBoxColumn and AutoCompleteMode, AutoCompleteSource property.....?
• rebind datagrid in Visual C# 2003
• how to show records as per in else condition in sql
• change value of an unbound DataGridViewCheckBoxColumn element
• Run a query in MS Access from VB.NET
• DataGridView: Question about DataGridViewComboBoxColumn and accessing the Click event
• How to programmatically select an item from a ComboBox?
• Drag-Drop on Panel...
• How to change position in a binding source.