问题描述
我有一组名为cmbSingle1, cmbSingle2,cmbSingle3等的组合框。
I have a set of combo boxes named cmbSingle1, cmbSingle2, cmbSingle3, etc.
没有必要在这些组合框中选择任何内容,但如果选择至少一个任务将被执行。
It's not necessary to select anything in those combo boxes, but if at least one is selected some task will be executed.
如果没有选择任何任务,将执行另一个任务。
If none is selected another task will be executed.
那么怎么办呢?
我想我可以检查包含"Single"的所有组合框,然后检查all是否设置为"SelectedIndex == -1",然后没有选择任何值。
I suppose I could check all combo boxes containing "Single", and then check if all is set to "SelectedIndex == -1", then no value is selected.
怎么办呢?
推荐答案
>>但如果选择了至少一个,则会执行某项任务,如果未选择任何任务,则会执行另一项任务。
>>but if at least one is selected some task will be executed, If none is selected another task will be executed.
我认为您可以通过添加if语句来确定是否选择了值来执行某些操作:
I think you can do some operation through adding a if statement to determine whether a value is selected:
private void button1_Click(object sender, EventArgs e)
{
if (comboBox1.Text.Trim().Length != 0 || comboBox2.Text.Trim().Length != 0|| comboBox3.Text.Trim().Length != 0|| comboBox4.Text.Trim().Length != 0)
{
MessageBox.Show("Comboboxes are not empty, There is data selected");
}
else
{
MessageBox.Show("Comboboxes are empty, There is not data selected");
}
}
希望这会有所帮助!
Hope this helps!
最好的问候,
Stanly
这篇关于如果选择了值,请选中多个组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!