VBobCat
Well-known member
Hello People!
My application has several ComboBox whose DataSource properties are always DataTable with two columns, one contains the PrimaryKey, and its name ("PK") is set in ComboBox.ValueMember property, and the other contains text descriptions, and its name ("ITEM") is set in ComboBox.DisplayMember property. So far, so good.
Well, the lists of options are huge, so I created an auxiliary DialogBox which the user can open for each ComboBox. This DialogBox has a TextBox and a ListBox, and OK and Cancel buttons as well. The ListBox.DataSource is initially set to be the same as the ComboBox in which the user called for help.
My intention is to provide a list whose content narrows as the user inputs some text, in order to ease the search for one specific item. For that, I did this:
* ListaBase is the same datatable provided to be the DataSource for that paticular ComboBox.
This works, as long as I keep the filter as simple as that: '%(what the user typed)%', and the list will narrow to show only entries whose description contains the exact typed expression, whatever stands before and after.
It is already some help, but what I really wanted to have is this:
- if the user types more than one word, it will find descriptions even if there are other words between those typed (it is good enough if it matches only when the words appear in the same order, for there is a sense in it);
- if there are diacritics involved (they are common in Portuguese), the search will match near correspondences, for instance: if description has the word "execução" and user types "execucao", they match; and vice-versa, that is, if user types correctly a word that was put in database without the proper diacritics.
For the first accomplishment, I tried replacing each space in user's typing with an "%", so that typing, for instance, "expediente interno" would result this expression: "ITEM like '%expediente%interno%'"
For the second accomplishment, I wrote a replacement-function so that typing, for instance, "execução" would result this expression: "ITEM like '%[eéèëê]x[eéèëê]c[uúùüû][cç][aáàäâã][oóòöôõ]%'"
My problem is: both these options raise an error in this case, like this:
The error is handled, but then ListBox will show the entire original list (what I wanted to happen only if the expression was not found at all)
As I successfully used these syntaxes in my SQL expressions for my database queries, I thought I could use the same here. Obviously, I am wrong. Could someone help me with this? Thanks a lot!
My application has several ComboBox whose DataSource properties are always DataTable with two columns, one contains the PrimaryKey, and its name ("PK") is set in ComboBox.ValueMember property, and the other contains text descriptions, and its name ("ITEM") is set in ComboBox.DisplayMember property. So far, so good.
Well, the lists of options are huge, so I created an auxiliary DialogBox which the user can open for each ComboBox. This DialogBox has a TextBox and a ListBox, and OK and Cancel buttons as well. The ListBox.DataSource is initially set to be the same as the ComboBox in which the user called for help.
My intention is to provide a list whose content narrows as the user inputs some text, in order to ease the search for one specific item. For that, I did this:
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged Dim Filtro As String = "ITEM like '%" + TextBox1.Text.Trim.ToUpper & "%'" Try ListBox1.DataSource = ListaBase.Select(Filtro).CopyToDataTable Catch ex As Exception ListBox1.DataSource = ListaBase End Try If ListBox1.Items.Count > 1 Then ListBox1.ClearSelected() End Sub
* ListaBase is the same datatable provided to be the DataSource for that paticular ComboBox.
This works, as long as I keep the filter as simple as that: '%(what the user typed)%', and the list will narrow to show only entries whose description contains the exact typed expression, whatever stands before and after.
It is already some help, but what I really wanted to have is this:
- if the user types more than one word, it will find descriptions even if there are other words between those typed (it is good enough if it matches only when the words appear in the same order, for there is a sense in it);
- if there are diacritics involved (they are common in Portuguese), the search will match near correspondences, for instance: if description has the word "execução" and user types "execucao", they match; and vice-versa, that is, if user types correctly a word that was put in database without the proper diacritics.
For the first accomplishment, I tried replacing each space in user's typing with an "%", so that typing, for instance, "expediente interno" would result this expression: "ITEM like '%expediente%interno%'"
For the second accomplishment, I wrote a replacement-function so that typing, for instance, "execução" would result this expression: "ITEM like '%[eéèëê]x[eéèëê]c[uúùüû][cç][aáàäâã][oóòöôõ]%'"
My problem is: both these options raise an error in this case, like this:
VB.NET:
System.Data.EvaluateException was caught
Message=Error at operator Like: the pattern of the string '%EXPEDIENTE%INTERNO%' is not valid.
Source=System.Data
StackTrace:
em System.Data.LikeNode.AnalyzePattern(String pat)
em System.Data.LikeNode.Eval(DataRow row, DataRowVersion version)
em System.Data.Select.AcceptRecord(Int32 record)
em System.Data.Select.GetLinearFilteredRows(Range range)
em System.Data.Select.SelectRows()
em System.Data.DataTable.Select(String filterExpression)
em SASP.DialogSelItemLista.TextBox1_TextChanged(Object sender, EventArgs e)
InnerException:
As I successfully used these syntaxes in my SQL expressions for my database queries, I thought I could use the same here. Obviously, I am wrong. Could someone help me with this? Thanks a lot!