ComboBox.SelectedValue不匹配,在Windows 7中显示文本时,DropDownStyle = DropDownList的 [英] ComboBox.SelectedValue does not match displayed text when DropDownStyle = DropDownList in Windows 7

查看:187
本文介绍了ComboBox.SelectedValue不匹配,在Windows 7中显示文本时,DropDownStyle = DropDownList的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,我们有以下的code在Windows应用程序:

Let's say we have the following code in a Windows application:

ComboBox comboBox = new ComboBox()
{
    AutoCompleteMode = AutoCompleteMode.SuggestAppend,
    AutoCompleteSource = AutoCompleteSource.ListItems,
    DataSource = new string[] { "", "Ark", "Boat", "Bucket" },
    DropDownStyle = ComboBoxStyle.DropDownList
};
this.Controls.Add(comboBox);

TextBox textBox = new TextBox()
{
    Left = comboBox.Right,
    Top = comboBox.Top,
    ReadOnly = true
};
textBox.DataBindings.Add("Text", comboBox, "SelectedValue");
this.Controls.Add(textBox);

没有魔法在这里,只是一个code>组合框绑定到一个字符串列表。该文本框显示的SelectedValue 组合框的。

No magic here, just a ComboBox bound to a list of strings. The TextBox displays the SelectedValue of the ComboBox.

我收到意外的行为,当我输入斗到组合框和标签了。出于某种原因,组合框显示船,但文本框显示斗。我希望他们两个可以显示斗。

I'm getting unexpected behavior when I type "Bucket" into the ComboBox and tab away. For some reason the ComboBox displays "Boat" but the TextBox displays "Bucket". I would expect them both to display "Bucket".

它的行为如预期,如果我改变了 DropDownStyle 下拉,但我不希望用户可以键入任何他们想要的。它们应该只能够键入是列表中的项目。

It behaves as expected if I change the DropDownStyle to DropDown, but I don't want users to be able to type anything they want. They should only be able to type items that are in the list.

更有趣的是,键入斗和跨栏了,如果我输入斗后,再次将在都显示斗。如果我做了第三次尝试,它可以追溯到船为组合框和斗为'文本框'。因此,它好像它通过循环所有的B的。

Even more interesting is that, after typing "Bucket" and tabbing away, if I type "Bucket" again it will display "Bucket" in both. If I make a third attempt, it goes back to "Boat" for the ComboBox and "Bucket" for the `TextBox'. So it seems like it's cycling through all the B's.

我没有注意到这一点,直到我从XP升级到Windows 7日前。我不明白怎么可能有什么做这个,但我把它扔了呢。

I didn't notice this until I upgraded from XP to Windows 7 recently. I don't see how that could have anything to do with this, but I'm throwing it out anyway.

如果这种行为是正确的,谁能告诉我,我应该怎样做才能达到我预期的行为?

If this behavior is correct, can anyone tell me what I should be doing to achieve my expected behavior?

更新这似乎是这个的的有关Windows 7的一切行为与预期在Windows XP模式。任何人都运行Windows 7可以试试我的code和验证,我不是疯了?

UPDATE It would seem this is related to Windows 7. Everything behaves as expected in Windows XP Mode. Can anyone else running Windows 7 try my code and verify that I'm not crazy?

推荐答案

修补程序将解决这一问题。

这篇关于ComboBox.SelectedValue不匹配,在Windows 7中显示文本时,DropDownStyle = DropDownList的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆