[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

09/22/2003 at 09:10AM PDT, ID: 20745272
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.0

Need help getting combobox autocomplete to work right

Asked by bacon7181 in .NET

Tags: combobox, autocomplete

I found some code on CodeProject for autocompleting text typed into a combo box.  It worked okay but I need a much cleaner implementation.  So I modified the code I found and made it quite a bit more user friendly.  I still have one problem though.   When I type too fast, I will end up jumping ahead of the windows messages.

See normally the order is like this:
  GetText
  FindString
  SetText
  SetSelectionStart
  SetSelectionLength

but when I type too fast I get extra keyup/keydown messages in there.  For instance, if I get another key press between SetText and SetSelectionStart then the new character being added will be added to the end of the string instead of the start of the selection area.  Its very annoying to have to type slow just so your autocomplete feature will work.

I need a way to set Text, Selection Start and Selection Length all at once or I need a way to hold (not ignore) all key messages until I'm sure all my messages have been processed.

Below is the code I am using.



    Public Sub AutoCompleteCombo_KeyUp(ByVal cbo As ComboBox, ByVal PreserveCase As Boolean, ByVal e As KeyEventArgs)
        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, Keys.Home, Keys.End, _
                 Keys.ShiftKey, Keys.ControlKey, Keys.Tab
                Return
            Case Keys.Escape
                cbo.SelectedText = ""
                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)

            If PreserveCase Then
                cbo.Text = sTypedText & sAppendText
            Else
                cbo.Text = sFoundText
            End If

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

        End If

    End Sub


    Public Sub AutoCompleteCombo_Leave(ByVal cbo As ComboBox)
        Dim iFoundIndex As Integer

        iFoundIndex = cbo.FindStringExact(cbo.Text)
        cbo.SelectedIndex = iFoundIndex
    End Sub

    Public Sub AutoCompleteCombo_Enter(ByVal cbo As ComboBox)
        cbo.SelectionStart = 0
        cbo.SelectionLength = Len(cbo.Text)
    End Sub
[+][-]09/22/03 09:21 AM, ID: 9406832

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: .NET
Tags: combobox, autocomplete
Sign Up Now!
Solution Provided By: morphinex
Participating Experts: 1
Solution Grade: A
 
 
[+][-]09/22/03 11:02 AM, ID: 9407599

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091028-EE-VQP-88