如何在Winform应用程序中阻止用户在Combobox中编写 [英] How Do I Prevent The User From Writing In Combobox In Winform App

查看:63
本文介绍了如何在Winform应用程序中阻止用户在Combobox中编写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的winform应用程序中有出生日期的组合boxex,这些框中的默认文本是日,月和年,我如何阻止用户写入它以及如何在没有值的情况下执行检查未从组合框中选择??

i have combo boxex for date of birth in my winform app,the default text in these boxes are day,month and year,how can i prevent the user from writing in it and how can i perform check if none of the value is not selected from comboboxes??

推荐答案

在设计器视图中将组合框的 DropDownStyle 属性设置为 DropDownList 或按代码:

In designer view set your combo box's DropDownStyleproperty to DropDownList or by code:
myCombo.DropDownStyle = ComboBoxStyle.DropDownList;





您可以通过选中 SelectedIndex SelectedValue 属性来检查是否选择了某个值,这取决于您如何将数据填充到组合框中。





You can check whether some value is selected or not by checking SelectedIndex or SelectedValue property, it depends on how do you fill data into your combo boxes.

if(myCombo.SelectedIndex != -1)
{
    //do something
}

//or

if(myCombo.SelectedValue != null)
{
    //do something
}


设置您的组合为DropDownList:



Set your combo as DropDownList:

this.comboBoxType.DropDownStyle = ComboBoxStyle.DropDownList;


这篇关于如何在Winform应用程序中阻止用户在Combobox中编写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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