如何检查值是否在C#的comboBox中? [英] how to check if the values is in the comboBox in C#?

查看:89
本文介绍了如何检查值是否在C#的comboBox中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的组合框具有男性"& 如果用户未选择,则为女性,仅键入任何内容,错误提示必须输入"invalid input!".类似的内容

我的代码但是很烂,我不知道怎么了

if(comboBox.text!="male" || comboBox.text!="female")
{
messagebox.show("invalid!");
}

my combobox has the "male" & "female if the user did not select just type anything an error must prompt "invalid input!"something like that

my code but it sucks do not works i dont know whats wrong

if(comboBox.text !="male" ||comboBox.text !="female")
{
messagebox.show("invalid!");
}

推荐答案

try:
try:
if (comboBox.SelectedIndex == -1) { 
  messagebox.show("invalid!");
}


祝你好运!


Good luck!


这篇关于如何检查值是否在C#的comboBox中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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