Search code examples
.netvb.netcomboboxdata-entry

ComboBox, different behavior on Windows 7 and 8.1


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. On my Windows 8.1 machine various methods of selecting the letter pairs were tested, and all worked. When user testing began an appearance anomaly was noted when installed on Windows 7, though the functionality worked. Here is some code that demonstrates the problem:

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

To demonstrate the problem run the application and do the following, paying attention to what is displayed in ComboBox1.

'  Type ab
'  press Enter (selected value of combobox1 is ab)
'  press shift tab
'  Type ab
'  press Enter (selected value of combobox1 is now ac)

If you run this on Windows 7 ComboBox1 will have 'Ac' displayed, and if on 8 it will correctly show 'Ab'. My question is how do I get this to properly display on Windows 7? The debug shows the disconnect between display and actual values.


Solution

  • It's a bug of Windows 7, try installing the fix located in the following article:

    A combo box control selects an unexpected value in Windows 7 SP 1 or Windows Server 2008 R2