Need help.

I have a combobox (cmbCharge1) that gets populated by a text file. Inside the combobox, the data inside is laid out like this:

41-1A-1303: EXPIRED REGISTRATION

Now, autocomplete works fine, if I start typing in the statute (like the 41 part). But what I need is for it to autocomplete based of whats after the :

So if I type in EX, then everything starting with EX pops up.

Anyone have a code snippet?

codeorder commented: well written post +1

Recommended Answers

All 5 Replies

See if this helps.
1 ComboBox (with items as stated in your post)

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        With ComboBox1
            '//-- set for AutoComplete.
            .AutoCompleteSource = AutoCompleteSource.CustomSource
            .AutoCompleteMode = AutoCompleteMode.SuggestAppend '--\\
            AddHandler .Validating, AddressOf cmb_Validating '// add ComboBox to Validating Event.
        End With
        '// use this to load/reload the AutoCompleteList with the ComboBox items.
        loadMyCoolAutoCompleteList(ComboBox1)
    End Sub

    Private Sub loadMyCoolAutoCompleteList(ByVal selectedComboBox As ComboBox)
        With selectedComboBox
            .AutoCompleteCustomSource.Clear() '// Clear AutoCompleteList.
            For Each itm As String In selectedComboBox.Items '// loop thru all items in the ComboBox.
                .AutoCompleteCustomSource.Add(itm) '// add original item to your AutoCompleteList.
                '// locate the .Substring you want to add to the AutoCompleteList.
                itm = itm.Substring(itm.IndexOf(":") + 2) '// get all text following the ":" and the " " right after it.
                .AutoCompleteCustomSource.Add(itm) '// add .Substring of item to your AutoCompleteList.
            Next
        End With
    End Sub

    '// once the ComboBox Validates (looses focus), it will set the original item as .Text.
    Private Sub cmb_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
        Dim selectedComboBox As ComboBox = CType(sender, ComboBox)
        For Each itm As String In selectedComboBox.Items '// loop thru all items in the ComboBox.
            If itm.Substring(itm.IndexOf(":") + 2) = selectedComboBox.Text Then '// locate the .Substring that matches the .Text.
                selectedComboBox.Text = itm '// set .Text of ComboBox item.
                Exit For '// exit loop since done locating item.
            End If
        Next
    End Sub
End Class
commented: Again, mega kudos man!!! +1

Dang Codeorder, you've saved the day again! A huge public thanks- this guy has helped me more than anyone can imagine. He's gone above and beyond over and over and over to help me, and it's so much appreciated. Thanks dude!

commented: If heart.felt comment = True Then Return "thanx":) +12

Dang Codeorder, you've saved the day again! A huge public thanks- this guy has helped me more than anyone can imagine. He's gone above and beyond over and over and over to help me, and it's so much appreciated. Thanks dude!

Hi guys
I wanna do something similar, just my item names "format" is a little different, I have items named like:

250 green
red 250
bottle: 250

there is anything you can help me with?
thanks in advance

>>there is anything you can help me with?
.quite a bit, though let me think about it since you did not start your own.thread, linked to this, and p.m.'ed the link to "your" thread to the one that Solved this thread(.Me).
(tapping air keyboard, tappy, tappy :D)
k. done thinking.

Try .Replacing line.20 with: itm = itm.Substring(itm.IndexOf(" ") + 1) '// get all text following the " ". .andAlso .Replace line.30 with: If itm.Substring(itm.IndexOf(" ") + 1) = selectedComboBox.Text Then '// locate the .Substring that matches the .Text. Basically, it looks for the " " and not the ":" as in my previously posted.code.
You might, actually "you should" add something as: If itm.Contains(" ") Then... , just to make sure your app does not crash, w/my code. Keep it real now!

Hope this helps.:)

i have hundreds of items filled up in my combobox, i have kept autocomplete and suggest append properties on for combobox. it does searches the items only by there begining alphabets. i want it to search it from in between words too, plz help me out, am sry but i didnt understood your above answer properly.

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.