Click here to Skip to main content
15,886,046 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi everyone,

First of all I would like to thank you for the great articles we can find on this web site!

Well, I'm having a problem with the filter method of the binding source.
My idea is to use a combo box to select the column where the filter method is
going to look for the text inserted in a text box.

Here is my guess:
VB
Private Sub TextBox12_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox12.TextChanged

        Me.InventarioCompletoBindingSource.Filter = "(ComboBox1.Text) LIKE '" & TextBox12.Text & "%'"

End Sub

This gives me this error:
The column Combobox1 can't be found


Any ideas?

Thank you in advance
Posted
Updated 7-Dec-12 9:06am
v4
Comments
joshrduncan2012 7-Dec-12 13:13pm    
First of all, please tag your questions with appropriate tags (e.g. VisualStudio, language used, forms or web).

Have you instantiated a combobox1 either in design view or programmatically?
Albandsan 7-Dec-12 16:10pm    
I don't understand what you mean by "instantiated a combobox". I have a Combobox I've created in design view with a Collection that has the columns I want to filter.

I've already posted the tags as you told me, Thank you!
Nelek 7-Dec-12 16:06pm    
I recommend you to use the "reply" widget instead of posting a comment. If you use reply, the other person will get a notification (as you are getting one from this comment)
Albandsan 7-Dec-12 16:11pm    
Ok, thank you Nelek.
Nelek 7-Dec-12 16:12pm    
You are welcome

VB
Private Sub TextBox12_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox12.TextChanged

        Me.InventarioCompletoBindingSource.Filter = "(ComboBox1.SelectedItem.ToString()) LIKE '" & TextBox12.Text & "%'"

End Sub
 
Share this answer
 
Comments
Albandsan 8-Dec-12 6:26am    
Hi Krunal.

I've tried your code. I've selected an item from my collection in the combobox1
and then when I type my search in the textbox12 I get the following error:

Couldn't handle System.Data.EvaluateException
Message= The expression has an undefined function call ComboBox1.SelectedItem.ToString()

The names in the Collection are exactly the same as the names in the columns I want to search in. I'm missing something but I don't know what. Do you know why I get this error?

Thank you for your time.
[no name] 8-Dec-12 6:30am    
Actually I don't know much about VB, I've converted your code in C# and then I've provide solution to you...
Albandsan 8-Dec-12 7:37am    
I got the solution. The ComboBox1.SelectedItem.ToString combined with the if statement was the key.
It works! Thank you Krunal

I've combined the "Combobox1.selectedvalue.tostring" with the "if then" statement to handle every item in my combobox1 collection and also the posibility of it being nothing.

Here is what I did:

Quote:
Private Sub TextBox12_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox12.TextChanged

If ComboBox1.SelectedItem = Nothing Then
Me.InventarioCompletoBindingSource.Filter = "COD1 LIKE '" & TextBox12.Text & "%' OR EQUIPO LIKE '" & TextBox12.Text & "%' OR MARCA LIKE '" & TextBox12.Text & "%' OR MODELO LIKE '" & TextBox12.Text & "%' OR SERIE LIKE '" & TextBox12.Text & "%' OR UBICACION LIKE '" & TextBox12.Text & "%' OR ZONA LIKE '" & TextBox12.Text & "%' OR LUGAR LIKE '" & TextBox12.Text & "%'OR ESTADO LIKE '" & TextBox12.Text & "%'"
ElseIf ComboBox1.SelectedItem.ToString = "Equipo" Then
Me.InventarioCompletoBindingSource.Filter = "EQUIPO LIKE '" & TextBox12.Text & "%'"
ElseIf ComboBox1.SelectedItem.ToString = "Marca" Then
Me.InventarioCompletoBindingSource.Filter = "MARCA LIKE '" & TextBox12.Text & "%'"
ElseIf ComboBox1.SelectedItem.ToString = "Modelo" Then
Me.InventarioCompletoBindingSource.Filter = "MODELO LIKE '" & TextBox12.Text & "%'"
ElseIf ComboBox1.SelectedItem.ToString = "Serie" Then
Me.InventarioCompletoBindingSource.Filter = "SERIE LIKE '" & TextBox12.Text & "%'"
ElseIf ComboBox1.SelectedItem.ToString = "Ubicacion" Then
Me.InventarioCompletoBindingSource.Filter = "UBICACION LIKE '" & TextBox12.Text & "%'"
ElseIf ComboBox1.SelectedItem.ToString = "Zona" Then
Me.InventarioCompletoBindingSource.Filter = "ZONA LIKE '" & TextBox12.Text & "%'"
ElseIf ComboBox1.SelectedItem.ToString = "Lugar" Then
Me.InventarioCompletoBindingSource.Filter = "LUGAR LIKE '" & TextBox12.Text & "%'"
ElseIf ComboBox1.SelectedItem.ToString = "Estado" Then
Me.InventarioCompletoBindingSource.Filter = "ESTADO LIKE '" & TextBox12.Text & "%'"
ElseIf ComboBox1.SelectedItem.ToString = "Todos" Then
Me.InventarioCompletoBindingSource.Filter = "COD1 LIKE '" & TextBox12.Text & "%' OR EQUIPO LIKE '" & TextBox12.Text & "%' OR MARCA LIKE '" & TextBox12.Text & "%' OR MODELO LIKE '" & TextBox12.Text & "%' OR SERIE LIKE '" & TextBox12.Text & "%' OR UBICACION LIKE '" & TextBox12.Text & "%' OR ZONA LIKE '" & TextBox12.Text & "%' OR LUGAR LIKE '" & TextBox12.Text & "%'OR ESTADO LIKE '" & TextBox12.Text & "%'"
End If

End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900