3
Contributors
8
Replies
96
Views
5 Months
Discussion Span
Last Post by Xavier_5
0
Imports System.Collections
Imports System.Linq
Public Class searchInComboBox
    Public aC As New ArrayList
    Private Sub searchInComboBox_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        Try
            aC.AddRange(cboxDomains.Items.Cast(Of String).ToList())
        Catch ex As Exception
        End Try
    End Sub

    Private Sub cboxDomains_TextUpdate(sender As Object, e As System.EventArgs) Handles cboxDomains.TextUpdate
        Try
            Dim query = From str As String In aC Where
            str Like "*" + sender.text + "*"
            cboxDomains.Items.Clear()
            cboxDomains.Items.AddRange(query.ToArray)
            cboxDomains.DroppedDown = True
            cboxDomains.Select(Len(cboxDomains.Text), 0)
        Catch ex As Exception
        End Try
    End Sub
End Class
Here, autocomplete is not used and the list is in the combobox item property. On the load event the list is copied into the `aC`ArrayList and, then, on the TextUpdate event Linq does the work, selecting only those that verify the `Like`condition. 

cbox1.PNGcbox2.PNG

0
    Private Sub cboxDomains_TextUpdate(sender As Object, e As System.EventArgs) Handles cboxDomains.TextUpdate

        Try
            Dim txt As String = cboxDomains.Text
            Dim query = From str As String In aC Where
            str Like "*" + sender.text + "*"
            cboxDomains.Items.Clear()
            cboxDomains.Focus()
            cboxDomains.Items.AddRange(query.ToArray)
            cboxDomains.Select(Len(txt), 1)
            cboxDomains.DroppedDown = True
        Catch ex As Exception
        End Try
    End Sub

cbox3.PNGClick Here

1
Imports System.Collections
Imports System.Linq

Public Class searchInComboBox

    Public aC As New ArrayList
    Private Sub searchInComboBox_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        Try
            aC.AddRange(cboxDomains.Items.Cast(Of String).ToList())
        Catch ex As Exception
        End Try
    End Sub

    Private Sub cboxDomains_TextUpdate(sender As Object, e As System.EventArgs) Handles cboxDomains.TextUpdate
        Try
            With cboxDomains
                Dim query = From str As String In aC Where
                str Like "*" + .Text + "*"
                .Items.Clear()
                .Focus()
                .Items.AddRange(query.ToArray)
                Dim em As New MouseEventArgs( _
                    Windows.Forms.MouseButtons.Left, 1, 1, 1, 0)
                Cursor.Position = New Point( _
                    Me.Location.X + .Location.X + .Width / 2, _
                    Me.Location.Y + .Bottom)
                .Select(Len(.Text), 1)
            End With
            SendKeys.SendWait("%{down}{tab}")
        Catch ex As Exception
        End Try
    End Sub

End Class

I am sending the code again, because there was a problem with the cursor not showing when located outside of the form. Now, it seems solved.

cbox4.PNG

1

Of course instruction Dim em As New MouseEventArgs... does nothing: you may remove it. I am sorry for it.

0

Thanks for your answers. The 3-rd Code is almost work but not quite. The problem is when typing in combobox it accepts every second click. I was tryed figuere that out, but no success. And unfortunately the mouse at some point disappear. Can u doble checked for this? ... 10x again !

0

To avoid the mouse disappearing is what for SendKeys instruction stands. I have checked again and for me the code is working fine: when writing in the keyboard the search pattern, the mouse moves near the combobox, the dropdown shows the items meeting the 'Like' condition and the mouse remains visible. So here goes another time the code hopping it's ok and has no extra code (the {tab}had no need to be there):

Imports System.Collections
Imports System.Linq

Public Class searchInComboBox

    Public aC As New ArrayList
    Private Sub searchInComboBox_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        Try
            aC.AddRange(cboxDomains.Items.Cast(Of String).ToList())
        Catch ex As Exception
        End Try
    End Sub

    Private Sub cboxDomains_TextUpdate(sender As Object, e As System.EventArgs) Handles cboxDomains.TextUpdate
        Try
            With cboxDomains
                Dim query = From str As String In aC Where
                str Like "*" + .Text + "*"
                .Items.Clear()
                .Focus()
                .Items.AddRange(query.ToArray)
                Cursor.Position = New Point( _
                    Me.Location.X + .Location.X + .Width / 2, _
                    Me.Location.Y + .Bottom)
                .Select(Len(.Text), 1)
            End With
            SendKeys.SendWait("%{down}")
        Catch ex As Exception
        End Try
    End Sub

End Class
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.