Solved

F1 F1 F1 --- Combo box issue

Posted on 2004-08-12
5
228 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 Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.Net - Project Software to help the Developer 7 40
Store results in vb.net 3 25
How do sunrise and sunset times change with altitude 14 38
FInd Image Control Gridview 3 23
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

820 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