7 Years
Discussion Span
Last Post by Santanu Das

That function is not available in the standard ComboBox.
You will have to do some overriding of your own.
This project on CodeProject will guide you in the right direction.
Although written in C#, it's a simple thing to convert to VB.NET.


Two to three years ago I wrote a small codification to search strings in an array for a part of string (where may be it reside).

First I loaded an Array by some values running a Loop. You can load your data from database into the Array.
Write the part of the string and press Enter. After pressing Enter, the strings (which contains the string part) are added into the list of the ComboBox.

You can use that to solve your self.

Public Class Form1
    Dim MainArray() As String

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub loadArray()
        ' loading data in an Aray 
        ReDim MainArray(0)
        For i As Integer = 1 To 32676
            ReDim Preserve MainArray(i)
            MainArray(i) = "X" & Format(i, "00000")
    End Sub

    Private Sub LoadCombo()
        ' Clear the ComboBox

        ' Now run a Loop to add selected items
        For i = 0 To UBound(MainArray)
            ' Check the condition
            If FindString(MainArray(i), ComboBox1.Text) Then
                ' Add the correct string to the ComboBox
            End If

    End Sub
    Private Sub ComboBox1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyDown
        'Write the substring adn press  enter
        If e.KeyCode = Keys.Return Then
        End If
    End Sub

    Private Function FindString(ByVal fText As String, ByVal xText As String) As Boolean

        ' Searching the string in which the part is included
        Dim Result As Boolean = False

        For i As Integer = 1 To (Len(fText) - Len(xText) + 1)
            If Mid(fText, i, Len(xText)) = xText Then
                Result = True
                Exit For
            End If

        Return Result
    End Function

End Class
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.