Search code examples
c#vb.netcomboboxon-screen-keyboardsuggestbox

ComboBox Suggestion Based On On-Screen Keyboard In .NET


I am developing an application in VB.NET, but the answer could be C#-based also. My problem is: I have a combobox for filtering some data and I am required to implement the search suggestions based on what was previously written (like the Google search bar). If the user inserts the filtering criteria from the pyshical keyboard everything is fine (as I set the AutoCompleteMode on Suggest and the AutoCompleteSource on ListItems). But the application I am working on also provides the user a numerical on-screen keyboard, something like this:

enter image description here

If any code sample is needed, I'll provide, but the functionality of the keyboard is simple: take the written text, append the last pressed key, overwrite the textbox with the new, appended text. So far, when the user inserts input from this on-screen keyboard, the suggestions are not displayed anymore. Is there any way to achieve the same behaviour with the on-screen keyboard, just like it does with the physical one? Thanks, have a nice day!

Edit: here is the code for the way the keypad works:

Private Sub AppendKey (ByVal key As String)
    Dim str1 As String = cboFilter.Text
    str1 = str1 & key 
    cboFilter.Text = str1
    cboFilter.Focus()
    cboFilter.SelectionStart = cboFilter.Text.Length 
End Sub 

Solution

  • As suggested by Jimi, I will post the solution I found here as an answer, in case somebody else lands on this issue as well. In case the keypad is used for this particular combobox, I added a call to the following new created Sub in the provided Sub:

    Private Sub AppendKey (ByVal key As String)
        If currentCbo = cboFilter Then 
            'currentCbo holds the currently editting combobox'
            AppendKeyInFilterCbo(key)
        Else 
            'The normal behaviour for the other comboboxes'
            Dim str1 As String = currentCbo.Text
            str1 = str1 & key 
            currentCbo.Text = str1
            currentCbo.Focus()
            currentCbo.SelectionStart = currentCbo.Text.Length 
        End If 
    End Sub 
    
    Private Sub AppendKeyInFilterCbo (ByVal key As String)
        cboFilter.Focus()
        cboFilter.SelectionStart = cboFilter.Text.Length
        SendKeys.Send("{" + key + "}")
    End Sub 
    

    This behaviour was needed only for the filter combobox because it is the only one where suggestions make sense for the user.