在多个组合框上选择索引更改hv以启用按钮 - C#

时间:2012-07-27 10:36:34

标签: c#

我有8个comboboxes,如果用户更改combobox值中的任何一个,我必须启用一个按钮。 我为每个组合框添加了SelectedIndexChanged事件。并尝试像这样检查。

if (
  cmbDInput_SelectedIndexChanged || cmbSwitch_SelectedIndexChanged ||
  cmbSatName_SelectedIndexChanged || cmbDRepeat_SelectedIndexChanged ||
  cmbSeq_SelectedIndexChanged
)

但它会抛出错误

  

运算符||无法应用于“方法组”和“方法组”类型的操作数

有任何建议怎么做?

1 个答案:

答案 0 :(得分:0)

如果语句表达式cmbDInput_SelectedIndexChanged运算符应该应用于布尔值,那么您正在使用方法名称,即事件||

if ((cmbDInput_SelectedIndexChanged) || cmbSwitch_SelectedIndexChanged || cmbSatName_SelectedIndexChanged || cmbDRepeat_SelectedIndexChanged || cmbSeq_SelectedIndexChanged)

将是

if ((cmbDInput.SelectedIndex !- -1) || cmbSwitch.SelectedIndex != -1|| cmbSatName.SelectedIndex !- -1 || cmbDRepeat_.SelectedIndex != -1 || cmbSeq.SelectedIndex != -1)

或者你可以得到事件的来源,即所选索引的组合如下改变

protected void cmbDInput_SelectedIndexChanged(object sender, System.EventArgs e)
{
    ComboBox ChangedCombox = sender as ComboBox;
}