【发布时间】:2021-05-31 09:59:19
【问题描述】:
我想填充组合框2,但考虑到组合框1上选择的值; 例如,如果选择组合框 1 的值 1;自动组合框2将填充值“a”和“b”....
private void combobox1_SelectedIndexChanged(object sender, EventArgs e)
{
int selectedIndex = combobox1.SelectedIndex;
if (selectedIndex == 1)
{
combobox1.Items.Clear();
combobox1.Items.Add(" a");
combobox1.Items.Add("b");
}
else if (selectedIndex == 2)
{
combobox2.Items.Clear();
combobox2.Items.Add("c");
combobox2.Items.Add("d");
}
}
显示此错误:
System.ArgumentOutOfRangeException:'InvalidArgument='0' 的值对'SelectedIndex' 无效。 参数名称:SelectedIndex'
如果有人有任何想法,他们可以帮助我们解决这个问题;谢谢
【问题讨论】:
-
请阅读how-to-ask page和How to create a Minimal, Complete, and Verifiable example以改进您的问题并帮助我们了解您的问题。
标签: c# asp.net visual-studio winforms