下拉组合框时停止更改文本

问题描述 投票:1回答:1

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

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

enter image description hereenter image description here

请注意,如果用户未按下拉菜单,则“ X”将留在组合框中。

请注意,这里有一个相似的问题,但实际上是不同的。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?

c# winforms combobox
1个回答
0
投票

我认为此解决方案应为您提供帮助:

Winforms combobox bug - 2 items with the same value but different key

if (m.Msg == LB_FINDSTRING)更改为m.Msg = LB_FINDSTRINGEXACT;,这应防止您描述的行为。

© www.soinside.com 2019 - 2024. All rights reserved.