如何检查项目是从C#中的组合框选择 [英] how to check if item is selected from a comboBox in C#
本文介绍了如何检查项目是从C#中的组合框选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,我很新在这里。
Hi all, I'm pretty new here.
我有一个表格,并要检查,如果用户正确填写了。在窗体有一个组合框;我怎么能打造的if语句来检查用户是否从中挑一个项目?
I have a form, and want to check if the user filled it in correctly. In the form there's a combo box; how can I build the "if" statement for checking whether the user picked an item from it ?
P.S。对不起,我的英语不好,这不是我母亲的语言。 :)
P.S. Sorry for my bad English, it's not my mother's language. :)
推荐答案
使用:
if(comboBox.SelectedIndex > -1) //somthing was selected
要获得选择的项目你做的:
To get the selected item you do:
Item m = comboBox.Items[comboBox.SelectedIndex];
由于马修正确地指出,要获得所选择的项目你也可以做
As Matthew correctly states, to get the selected item you could also do
Item m = comboBox.SelectedItem;
这篇关于如何检查项目是从C#中的组合框选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文