ComboBox.SelectedValue不匹配,在Windows 7中显示文本时,DropDownStyle = DropDownList的

编程入门 行业动态 更新时间:2024-10-11 07:25:17
本文介绍了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的

本文发布于:2023-11-06 08:47:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1563220.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不匹配   文本   ComboBox   SelectedValue   DropDownList

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!