Results 1 to 13 of 13

Thread: [RESOLVED] ComboBox Behavior - error/bug

  1. #1

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,754

    Resolved [RESOLVED] ComboBox Behavior - error/bug

    Create a combobox and add the following to the Items collection

    Ab
    Ac
    Ad
    El
    En

    Set the following properties
    DropDownStyle = DropDownList
    AutoCompleteSource - ListItems
    AutoCompleteMode = Suggest

    Then copy and paste the combobox

    Then add the following code

    Code:
        Private Sub ComboBox1_SelectionChangeCommitted(sender As Object, e As EventArgs) Handles ComboBox1.SelectionChangeCommitted
            Debug.WriteLine(ComboBox1.SelectedIndex)
            Debug.WriteLine(ComboBox1.Text)
            ComboBox2.Select()
        End Sub
    
        Private Sub ComboBox2_Enter(sender As Object, e As EventArgs) Handles ComboBox2.Enter
            Debug.WriteLine(ComboBox1.SelectedIndex)
            Debug.WriteLine(ComboBox1.Text)
        End Sub
    Run it.

    Type ab then enter, then shift tab, then ab, then enter. If you are running Windows 7 the combobox1 says Ac, if you are running Windows 8.1 it says Ab. In all cases the debug shows the correct values(0 and Ab).
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: ComboBox Behavior - error/bug

    It appears to be cycling through the list... if you keep going it'll select Ac then Ad then back around to Ab... it also does this if you just press "a" each time in the combo box. So that may have something to do with it.
    If you change it to SuggestAppend... when you shift-tab back into ComboBox1, and just press "a" ... you'll see that it selects "Ac" I suspect it has to do with how it's processing the keystrokes.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: ComboBox Behavior - error/bug

    Why would you set auto-complete properties if the DropDownStyle is DropDownList?

  4. #4

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,754

    Re: ComboBox Behavior - error/bug

    Quote Originally Posted by jmcilhinney View Post
    Why would you set auto-complete properties if the DropDownStyle is DropDownList?
    The combobox is to allow the user to select a pair of letters and when they press enter it uses those values to load the second combobox with items from a DB that start with the letter pair. When I deployed this app that was developed on Win 8.1 to a Win 7 machine I found this anomaly. If the autocomplete is set to none then the first letter causes the event to fire.

    Quote Originally Posted by techgnome View Post
    It appears to be cycling through the list... if you keep going it'll select Ac then Ad then back around to Ab... it also does this if you just press "a" each time in the combo box. So that may have something to do with it.
    If you change it to SuggestAppend... when you shift-tab back into ComboBox1, and just press "a" ... you'll see that it selects "Ac" I suspect it has to do with how it's processing the keystrokes.

    -tg
    Yes that is what it does. On Win 8.1 I don't see this behavior.



    Did you notice the debug?
    Last edited by dbasnett; Jul 23rd, 2014 at 08:45 AM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  5. #5

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,754

    Re: ComboBox Behavior - error/bug

    The problem only occurs if I .Select the other combobox. If you comment out ComboBox2.Select() and do this the problem doesn't happen.
    type ab
    press enter
    press tab
    press shift tab
    type ab
    press enter
    press tab
    press shift tab
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  6. #6

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,754

    Re: ComboBox Behavior - error/bug

    I have several confirmations of how this behaves on the two platforms, but no resolutions.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  7. #7

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,754

    Re: ComboBox Behavior - error/bug

    Here is what this is about.

    I am re-writing an application, in VB 2012, that manages / edits / prints an index of statutes. This is an index like you might find in the back of a book but it has 2500 major entries, such as Elections, Taxation, Schools, etc. There are over 190,000 entries that fit under the major entries. When printed it takes four volumes.

    To aid the users the application takes the 2500 major entries and determines which pairs of letters are present based on the starting two letters of the major entries. Those letter pairs are loaded into a combobox. When the user selects a pair of letters another combobox is filled in with the major entries that start with those letters.

    If this can't be fixed, or even if it can, is there a better way to help the user navigate the system?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: ComboBox Behavior - error/bug

    I ask again, why would you be setting auto-complete properties if the DropDownStyle is DropDownList? DropDownList means that the user can only select an item and can't type text into the control. In fact, I just tried to set the AutoCompleteMode to Suggest when the DropDownStyle was DropDownList and the designer wouldn't let me. If you want to be able to use auto-complete then the user has to be able to type into the control, so the DropDownStyle has to be DropDown. Maybe you should just be using a TextBox with auto-complete on and forget about the drop-down list altogether.

  9. #9

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,754

    Re: ComboBox Behavior - error/bug

    Maybe this will help. They have to be set in a certain order. When I get to work I'll see if I can use a textbox to accomplish this.

    Code:
        Private Sub LoadMe(sender As Object, e As EventArgs) Handles MyBase.Load
    
            'some letter pairs
            ComboBox1.Items.AddRange(
                New String() {"Ab", "Ac", "Ad", "Az", "El", "En"})
    
            ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
            ComboBox1.AutoCompleteSource = AutoCompleteSource.ListItems
            ComboBox1.AutoCompleteMode = AutoCompleteMode.Suggest
    
            ComboBox2.Items.AddRange(
                New String() {"Ab", "Ac", "Ad", "Az", "El", "En"})
    
            ComboBox2.DropDownStyle = ComboBoxStyle.DropDownList
            ComboBox2.AutoCompleteSource = AutoCompleteSource.ListItems
            ComboBox2.AutoCompleteMode = AutoCompleteMode.Suggest
    
            ActiveControl = ComboBox1
        End Sub
    
        Private Sub ComboBox1_SelectionChangeCommitted(sender As Object, e As EventArgs) Handles ComboBox1.SelectionChangeCommitted
            Debug.WriteLine("CB1Committed Index: [{0}] Text: [{1}]",
                              ComboBox1.SelectedIndex,
                              ComboBox1.Text)
            ComboBox2.Select()
        End Sub
    
        Private Sub ComboBox2_Enter(sender As Object, e As EventArgs) Handles ComboBox2.Enter
            Debug.WriteLine("Enter Index: [{0}] Text: [{1}]",
                              ComboBox1.SelectedIndex,
                              ComboBox1.Text)
        End Sub
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  10. #10

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,754

    Re: ComboBox Behavior - error/bug

    I tried the textbox approach, and the interface is not good. I didn't mention this before, and maybe I should have. If the mouse is used to make selections in the combobox it displays properly. There are 177 letter pairs in the combobox in the real system.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  11. #11

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,754

    Re: ComboBox Behavior - error/bug

    This behavior is a known bug as it turns out.

    http://support.microsoft.com/kb/2868238/en-us
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  12. #12

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,754

    Re: ComboBox Behavior - error/bug

    This behavior is a known bug as it turns out.

    http://support.microsoft.com/kb/2868238/en-us
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  13. #13

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,754

    Re: ComboBox Behavior - error/bug

    I did find a workaround.
    Code:
        Private Sub ComboBox1_SelectionChangeCommitted(sender As Object, e As EventArgs) Handles ComboBox1.SelectionChangeCommitted
            Debug.WriteLine("CB1Committed Index: [{0}] Text: [{1}]",
                              ComboBox1.SelectedIndex,
                              ComboBox1.Text)
            Dim foo As Integer = ComboBox1.SelectedIndex '<<<<<fix
            ComboBox2.Select()
            ComboBox1.SelectedIndex = foo '<<<<fix
        End Sub
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width