Home > Net >  Implement fuzzy query in the combobox
Implement fuzzy query in the combobox

Time:11-23

Everyone a great god, and I want to achieve in the combobox to realize fuzzy query, find the code from the Internet, in the process of running a "DataRowView" from type to type "String" transformation is invalid, how can I solve,
 Private Sub ComboBox1_TextChanged (ByVal sender As System. Object, ByVal e the As System. EventArgs) Handles ComboBox1. The TextChanged 
Get the input string
Dim the text As String=ComboBox1. Text. The Trim ()
'is used to record the number of matching string
Dim index As an Integer=0
Dim listBox1 As New ListBox
'list_Pd is to define the global Boolean variables, is used to determine whether to create a listbox control
If list_Pd Then 'If you have created
For Each contr As Control In Me. Controls' traverse all Controls In the form For create the listbox Control
If contr. Name="list" Then
ListBox1=CType (contr, ListBox)
End the If
Next
The Else 'without creating, call the Custom_ListBox () function creates
ListBox1=Custom_ListBox (ComboBox1)
End the If
'the listbox control all items to empty
ListBox1. Items. The Clear ()
'add the results of a query to the listbox items in
For Each Str As String In ComboBox1. Items
'all the strings that will be all converted to lowercase, again without input points case
If Not text="And" Str. ToLower. The Contains (text. ToLower) Then
Index +=1
ListBox1. Items. The Add (Str)
End the If
Next
The number of eligible items' judgment,
If the index=1 Then
ComboBox1. Text=listBox1. Items (0)
ListBox1. Visible=False
ElseIf index & gt; 1 Then
ListBox1. Visible=True
The Else
ListBox1. Visible=False
End the If
End Sub
'to automatically create the listbox control function
Private Function Custom_ListBox (ByVal ComBox As ComboBox) As ListBox
Dim Listbox As New Listbox
Dim point As point
. Point X=ComBox. Location. X
Point. The Y=ComBox. Location. Y + ComBox. Height
With Listbox
.name="list" 'Settings control Name
. Location=point 'sets the position of the control, under the combobox
. Width=ComBox. Width 'controls the Width of the like combobox wide
. Height=ComBox. Height * (ComBox. Items. The Count + 1) highly
'. The Items. The Clear ()
The Visible=False
End With
AddHandler Listbox. Click AddressOf ListBox_Click 'add a Click event ListBox_Click ()
Me. Controls. The Add (Listbox) 'this important Add Controls to the form, no it will not be displayed Listbox control
List_Pd=True
Return the Listbox
End the Function
'create the listbox click event function
Private Sub ListBox_Click (ByVal sender As System. Object, ByVal e the As System. EventArgs)
CType (sender, ListBox.) Visible=False
ComboBox1. Text=CType (sender, ListBox.) SelectedItem
End Sub

CodePudding user response:

Combobox is binding the DataTable, you can traverse the DataTable
 
Foreach DataRow Dr In dt. Rows//about this

CodePudding user response:

Combobox if it is a plain text will not go wrong, it is estimated that you are binding the data source, if it is binding the data source, can be solved according to the above method,

CodePudding user response:

1, with a textbox on the side as a fuzzy query input device,
2, binding the datatable into dataview, then use dv filtering,

  • Related