Solved

F1 F1 F1 --- Combo box issue

Posted on 2004-08-12
5
227 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Duplicating a tab page content to another in TabControl control 11 44
Put window Form inside tab page 10 33
VB.NET Repostiory Pattern 7 37
get row value in vb.net 4 14
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 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