Sub routine to findstring in combobox

bnbunch

Member
Joined
Sep 29, 2015
Messages
5
Programming Experience
3-5
I have following code to search combobox which I need to repeat in different forms and different comboboxes

I am using from key up event

Private Sub ComboBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyUp

' Store the actual text that has been typed.
actual = Me.ComboBox1.Text
Me.TextBox1.Text = Me.ComboBox1.Text

' Find the first match for the typed value.
index = Me.ComboBox1.FindString(actual)
TextBox2.Text = Me.ComboBox1.FindString(actual)

' Get the text of the first match.
If (index > -1) Then
found = Me.ComboBox1.Items(index).ToString()
Me.TextBox2.Text = found
' Select this item from the list.
Me.ComboBox1.SelectedIndex = index

' Select the portion of the text that was automatically
' added so that additional typing will replace it.
Me.ComboBox1.SelectionStart = actual.Length
Me.ComboBox1.SelectionLength = found.Length
End If

end sub

I would like to repeat by passing my combobox name to a subroutine so i don't have to repeat this code each time
Is this possible?
 
Autocomplete is limited to a small font and is slow responding after click

The posted code works great just wanted a way create a sub that could be called from each different combobox so I don't have to repeat code for each combobox
 
You can add more controls to the Handles list, and can identify which control raised the event with the 'sender' parameter.
 
    Private Sub ComboBoxes_KeyUp(sender As Object, e As KeyEventArgs) Handles ComboBox1.KeyUp, ComboBox2.KeyUp
        MessageBox.Show(CType(sender, ComboBox).Name)
    End Sub
 
Back
Top