I re-post a thread which many others submitted times ago, but never got solutions or good answers! I re-new the challenge :)

http://www.daniweb.com/forums/thread226795.html
The last post gives an idea.

Another is here http://www.daniweb.com/forums/thread104261.html

I mean: editable dropdown boxes autocomplete function works with a so builded filter:

LIKE 'string%'

what WE want is to have

LIKE '%string%'

(SQL guys understand well ;) )

Thanks to all

Recommended Answers

All 3 Replies

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
        ComboBox1.Items.Clear()
        Me.loadArray()

    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")
        Next
    End Sub

    Private Sub LoadCombo()
        ' Clear the ComboBox
        ComboBox1.Items.Clear()

        ' 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
                ComboBox1.Items.Add(MainArray(i))
            End If
        Next

    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
            Me.LoadCombo()
        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
        Next

        Return Result
    End Function

End Class
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.