当列表项目以与下拉项目相同的文本开头时,如何设置ComboBox默认*不在下拉列表中? [英] 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?

查看:142
本文介绍了当列表项目以与下拉项目相同的文本开头时,如何设置ComboBox默认*不在下拉列表中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用C#,假设你有一个ComboBox的DropDownStyle设置为DropDown(下拉列表中有项目,但用户也可以手动输入一个值)。如何在下拉列表中的值列表中为组合框设置不是的默认值,但从可能的选项中选择 文本?通常设置ComboBox.Text工作正常,但如果在下拉列表中以开头的文本作为默认文本,它会自动选择列表中以文本开头的第一个项目。例如:

Using C#, say you have a ComboBox that has a DropDownStyle set to DropDown (there are items in the drop down but the user can manually enter a value as well). How do you set a default value for the ComboBox that is not in the list of values in the drop down, but begins with text from a possible selection? Normally setting ComboBox.Text works fine, but if there is an item in the drop down that begins with the text you want as the default, it automatically selects the first item in the list that starts with the text. For example:

下拉菜单中的值:

c:\program files \

c:\windows\

d :\media\

默认值分配

myComboBox.Text =C:\;

结果

当窗体打开时ComboBox的值为 c:\program files\

我做错了?如何正确设置不在下拉列表中以可能的选择开头的项目的默认值?

So what am I doing wrong? How do I correctly set a default value of an item not in the drop down list that begins with a possible selection?

推荐答案

不能重现你正在描述的行为。通过Items集合添加三个值,然后将初始值设置为c:\(您的代码示例中省略了一个@)顺利工作。我的猜测是,你的代码中的别的东西在设置组合框的值后设置它。

I couldn't repro the behavior you are describing. Adding the three values via the Items collection and then setting the initial value to "c:\" (you omitted an @ in your code sample, by the way) worked fine. My guess is that something else in your code is setting the value of the combo box after you set it.

这篇关于当列表项目以与下拉项目相同的文本开头时,如何设置ComboBox默认*不在下拉列表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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