Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo Box Selection Problem

Status
Not open for further replies.

Ragnarox

Programmer
Oct 2, 2003
141
US
Hello all,

I have numerous combo boxes in my program where users can type in and as they are typing the closest match appears. The problem is that once the first key is pressed and a match is found by the FindString method, that is what the program holds onto, even if that is not what is finally choosen. This only happens if you type in till the correct item appears and the tab out, yet if they click on the item then that item is correctly remembered.

How do I fix this problem so that the correct item is remembered through typing only.

Here is the code I am using that is causing the problem :
Code:
        Try
            Select Case e.KeyCode
                Case Keys.Back, Keys.Left, Keys.Right, Keys.Up, Keys.Delete, Keys.Down, Keys.Home, Keys.End
                    Return
            End Select

            strEntry = cboUserName.Text
            intFoundIndex = cboUserName.FindString(strEntry)

            If intFoundIndex >= 0 Then
                cboUserName.DroppedDown = True
                objFoundItem = cboUserName.Items(intFoundIndex)
                strFoundText = cboUserName.GetItemText(objFoundItem)
                strAppendText = strFoundText.Substring(strEntry.Length)
                cboUserName.Text = strEntry & strAppendText
                cboUserName.SelectionStart = strEntry.Length
                cboUserName.SelectionLength = strAppendText.Length
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Information, "Information")
        End Try



Any help, as always, is greatly appreciated.

Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top