Solved

F1 F1 F1 --- Combo box issue

Posted on 2004-08-12
5
220 Views
Last Modified: 2010-04-23
Hi,

I have created a custom combo box control. It goes to the matching entry in the list as you type. It works great all times BUT if the combo is dropped down (combo.DroppedDown = True) and the user types in an item  & hits TAB key then it does not work.

When the user types with drop-down portion visible, it correctly selects the matching item and displays but when the user hits TAB it goes to the previous item that was selected in the combo and not the new item. Surprisingly on the combo's lostfocus/leave, when I do combo.selectedValue I get the correct value of new item but it just does not select and highlight the new item in the combo.

Any help would be greatly appreciated.

Thanks!
0
Comment
Question by:jmnason
  • 2
5 Comments
 
LVL 27

Expert Comment

by:planocz
ID: 11783712
Are you wanting to go to the next control when you press tab?
0
 

Author Comment

by:jmnason
ID: 11783757
Yes. It goes to the next control correctly. The problem is the combo box is not highlighting/selecting the newly selected item.
0
 
LVL 27

Accepted Solution

by:
planocz earned 500 total points
ID: 11783819
Iam not sure which code you are using to select item.

Here is a sample of typeahead cbo code that I use that I think will work for you.
cbo is the comboBox control....

       Private Sub cbo_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cbo.KeyUp
            AutoCompleteCombo_KeyUp(sender, e)
        End Sub
        '********************* Better way of doing Type Head *************************
        Public Shared Sub AutoCompleteCombo_KeyUp(ByVal cbo As ComboBox, ByVal e As KeyEventArgs)
            '**************
            ' you can use it 2 ways.

            'either add the handles keyword after the sub name to handle your KeyUp event
            'eg. Public Shared Sub AutoCompleteCombo_KeyUp(ByVal cbo As ComboBox, ByVal e As KeyEventArgs) Handles cboSuburb.KeyUp

            'or

            'i use it as a generic sub so call it from the KeyUp event as follows:

            '  Private Sub cboSuburb_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cboSuburb.KeyUp
            '            AutoCompleteCombo_KeyUp(sender, e)
            '        End Sub
            '**************
            Dim sTypedText As String
            Dim iFoundIndex As Integer
            Dim oFoundItem As Object
            Dim sFoundText As String
            Dim sAppendText As String

            'Allow select keys without Autocompleting
            Select Case e.KeyCode
                Case Keys.Back, Keys.Left, Keys.Right, Keys.Up, Keys.Delete, Keys.Down
                    Return
            End Select

            'Get the Typed Text and Find it in the list
            sTypedText = cbo.Text
            iFoundIndex = cbo.FindString(sTypedText)

            'If we found the Typed Text in the list then Autocomplete
            If iFoundIndex >= 0 Then

                'Get the Item from the list (Return Type depends if Datasource was bound
                ' or List Created)
                oFoundItem = cbo.Items(iFoundIndex)

                'Use the ListControl.GetItemText to resolve the Name in case the Combo
                ' was Data bound
                sFoundText = cbo.GetItemText(oFoundItem)

                'Append then found text to the typed text to preserve case
                sAppendText = sFoundText.Substring(sTypedText.Length)
                cbo.Text = sTypedText & sAppendText

                'Select the Appended Text
                cbo.SelectionStart = sTypedText.Length
                cbo.SelectionLength = sAppendText.Length

            End If
        End Sub
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now