Question : Custom Combobox remains highlighted

I have a custom combobox in order to implement a "notinlist" type event.  It also ensures the tab key and enter key cause the combobox to trigger the SelectionChangeCommitted event (by overriding the OnLeave event).  All is working apart from one annoying feature. When the enter key is pressed, I have the code below move the focus to the next control. This works and triggers the SelectionChangeCommitted event.  

The problem is the next control has the focus as expected but leaves the combobox highlighted.  This does not happen with the TAB key.

Any ideas?

1:
2:
3:
4:
5:
6:
Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
        If keyData = Keys.Enter Then
            Me.Parent.GetNextControl(Me, True).Focus()
        End If
        Return MyBase.ProcessCmdKey(msg, keyData)
End Function

Answer : Custom Combobox remains highlighted

Hello, highwire,

Yes, that allows me to replicate the effect here as well.

Try putting:

    Me.SelectionLength = 0

into the custom ComboBox's ProcessCmdKey override.  This seems to work for me.  (See attached snippet for an example.)

Cheers,
Randy
1:
2:
3:
4:
5:
6:
7:
8:
    Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, _
                                               ByVal keyData As System.Windows.Forms.Keys) As Boolean
        If keyData = Keys.Enter Then
            Me.Parent.GetNextControl(Me, True).Focus()
            Me.SelectionLength = 0
        End If
        Return MyBase.ProcessCmdKey(msg, keyData)
    End Function
Random Solutions  
 
programming4us programming4us