Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Visual-Studio VB10.0 combobox , +
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:
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 7-Dec-12 7:36am
Edited 7-Dec-12 10:06am
v4
Comments
joshrduncan2012 at 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 at 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 at 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 at 7-Dec-12 16:11pm
   
Ok, thank you Nelek.
Nelek at 7-Dec-12 16:12pm
   
You are welcome
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Comments
Albandsan at 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.
Krunal Rohit at 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 at 8-Dec-12 7:37am
   
I got the solution. The ComboBox1.SelectedItem.ToString combined with the if statement was the key.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 539
1 Maciej Los 300
2 DamithSL 233
3 Sergey Alexandrovich Kryukov 209
4 BillWoodruff 200
0 OriginalGriff 7,168
1 Sergey Alexandrovich Kryukov 6,377
2 DamithSL 5,461
3 Manas Bhardwaj 4,876
4 Maciej Los 4,450


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 8 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100