本文介绍了C#使用文本验证组合框。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下午,
我的组合框验证有问题,我需要它,所以如果你在另一个组合框中选择爱丁堡两次它会显示错误信息。到目前为止这是我的代码。我希望有人可以提供帮助,对不起,如果不是很详细的话。
我尝试了什么:
Afternoon,
I have a problem with my combo box validation, I need it so if you select Edinburgh twice in another combo box it displays an error message. This is my code so far. I am hoping someone can help, sorry if it isn't very detailed.
What I have tried:
<pre>f (CmbDepa.Text == "Edinburgh" && CmbArrival.Text == "Edinburgh")
{
MessageBox.Show("You cant select edinburgh twice");
}
else
{
Listbox1.Items.Add(CmbDepa.Text);
}
}
}
推荐答案
if (CmbDepa.SelectedIndex == "Edinburgh") && (CmbArrival.SelectedIndex == "Edinburgh")
接下来,您不应该对预期的事物使用异常。例外是...例外:)忘记所有的尝试等,只显示一条消息
Next you shouldn't use exceptions for things that are expected. Exceptions are for...exceptions :) Forget all the trys etc, just show a message
if (CmbDepa.SelectedIndex == "Edinburgh") && (CmbArrival.SelectedIndex == "Edinburgh")
{
MessageBox.Show("You cant select edinburgh twice");
}
else
{
Listbox1.Items.Add(CmbDepa.Text);
}
这篇关于C#使用文本验证组合框。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!