下拉组合框时停止更改文本 [英] Stop changing text when combobox is dropped down

查看:27
本文介绍了下拉组合框时停止更改文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 WinForms.我有一个带有 DropDownStyle DropDown 的组合框.在项目中,我放了一个项目XA".当用户输入X"时进入组合框(尚未下拉),然后按下下拉按钮X";自动替换为XA".我怎样才能阻止这种情况发生?我希望用户能够将文本保留为X"并且只将文本更改为XA"如果XA"在下拉列表中被点击.要重新创建一个新的 WinForms 应用程序并添加一个组合框,然后添加以下代码

Using WinForms. I have a combobox with DropDownStyle DropDown. In the items I put a single item "XA". When the user enters "X" into the ComboBox (not yet dropped down) and then presses the drop down button "X" is automatically replaced with "XA". How can I stop this happening? I would like the user to be able to keep text as "X" and only change the text to "XA" if "XA" was clicked in the drop down list. To recreate create a new WinForms application and add a comboBox then add the following code

        private void Form1_Load(object sender, EventArgs e)
        {
            comboBox1.DropDownStyle = ComboBoxStyle.DropDown;
            comboBox1.Items.Add("XA");
        }

请注意,如果用户没有按下下拉菜单,则X"将显示在下拉菜单中.留在组合框中.

Note that if the user does not press the dropdown then "X" stays in the combobox.

请注意,这里有一个类似的问题,但实际上是不同的.当列表项以与下拉项相同的文本开头时,如何设置组合框默认值*不在下拉列表中*?

Note that there is a similar sounding question here but it is actually different. How do I set a ComboBox default *not in the drop down* when a list item begins with the same text as a drop down item?

推荐答案

我认为这个解决方案应该对您有所帮助:

I think this solution should help you:

Winforms组合框错误 - 2 个值相同但键不同的项目

它将 if (m.Msg == LB_FINDSTRING) 更改为 m.Msg = LB_FINDSTRINGEXACT;,这应该会阻止您描述的行为.

It changes if (m.Msg == LB_FINDSTRING) to m.Msg = LB_FINDSTRINGEXACT;, which should prevent the behavior you describe.

这篇关于下拉组合框时停止更改文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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