2

我正在用 VB 2012 重写一个应用程序,用于管理/编辑/打印法规索引。这是一个您可能会在书后找到的索引,但它有 2500 个主要条目,例如 Elections、Taxation、Schools 等。有超过 190,000 个条目适合主要条目。印刷时需要四卷。

为了帮助用户,应用程序获取 2500 个主要条目,并根据主要条目的前两个字母确定存在哪些字母对。这些字母对被加载到组合框中。当用户选择一对字母时,另一个组合框会填充以这些字母开头的主要条目。在我的 Windows 8.1 机器上测试了各种选择字母对的方法,并且都有效。当用户测试开始时,在 Windows 7 上安装时注意到外观异常,尽管该功能有效。这是一些演示问题的代码:

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

要演示问题,请运行应用程序并执行以下操作,注意 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)

如果您在 Windows 7 上运行此程序,ComboBox1 将显示“Ac”,如果在 8 上运行,它将正确显示“Ab”。我的问题是如何让它在 Windows 7 上正确显示?调试显示显示值和实际值之间的脱节。

4

2 回答 2

2

这是 Windows 7 的错误,请尝试安装以下文章中的修复程序:

组合框控件在 Windows 7 SP 1 或 Windows Server 2008 R2 中选择了意外的值

于 2014-07-24T19:46:22.493 回答
0

我确实找到了解决方法。

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
于 2014-07-25T09:33:33.967 回答