我怎样才能使ComboBox不可编辑在.net中? [英] How can I make a ComboBox non-editable in .net?

查看:130
本文介绍了我怎样才能使ComboBox不可编辑在.net中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有一个选择 - 只有组合框,提供项目列表供用户从中进行选择。键入应在组合框控件的文本部分被禁用。

I want to have a "select-only" ComboBox that provides a list of items for the user to select from. Typing should be disabled in the text portion of the ComboBox control.

我最初的这个谷歌搜索变成了一个过于复杂的,误导的建议,以捕捉键preSS 事件。

My initial Googling of this turned up an overly complex, misguided suggestion to capture the KeyPress event.

推荐答案

要使ComboBox不可编辑的文本部分,设置DropDownStyle属性为DropDownList的。组合框现在基本上是选择只为用户。您可以在Visual Studio设计做到这一点,或在C#这样的:

To make the text portion of a ComboBox non-editable, set the DropDownStyle property to "DropDownList". The ComboBox is now essentially select-only for the user. You can do this in the Visual Studio designer, or in C# like this:

stateComboBox.DropDownStyle = ComboBoxStyle.DropDownList;

链接到该文档<一href="http://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.dropdownstyle.aspx">ComboBox DropDownStyle属性 MSDN上。

这篇关于我怎样才能使ComboBox不可编辑在.net中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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