[英]InvalidArgument=Value '18' is invalid to 'SelectedIndex' Parameter name: SelectedIndex
I have a Button
where I am able to save data into the database. 我有一个
Button
,可以将数据保存到数据库中。 To do that I will get the information on Combobox
and on a Textbox
. 为此,我将在
Combobox
和Textbox
上获取信息。 I got a collection of items iniside of the Combobox
and cannot be changed at the moment. 我得到了项目iniside的的集合
Combobox
,并不能在瞬间不会改变。
Right now, I have 17 items and every time I save something it will pull to the next item using cmbID.SelectedIndex += 1;
现在,我有17个项目,每次保存时,它将使用
cmbID.SelectedIndex += 1;
拉到下一个项目cmbID.SelectedIndex += 1;
, but every time I pull to the last item from Combobox
it will give me an error : ,但是每次我从
Combobox
拉到最后一项时,都会给我一个错误:
InvalidArgument=Value '18' is invalid to 'SelectedIndex' Parameter name: SelectedIndex
InvalidArgument =值'18'对'SelectedIndex'无效参数名称:SelectedIndex
To solve it I've tried to use an if statement: 为了解决这个问题,我尝试使用if语句:
if (cmbID.SelectedIndex >= 18)
{
cmbID.SelectedIndex = 1;
}
But this is not working, basically if the Combobox
reach '18' it should go back to the SelectedIndex
choosen by me. 但这是行不通的,基本上,如果组合
Combobox
达到“ 18”,它应该回到我选择的SelectedIndex
。
Do you guys have any idea I can solve this problem? 你们有什么主意可以解决这个问题吗?
You can't have index more than (item count -1) for the combobox, so 组合框的索引不能超过(项目计数-1),因此
if(cmbID.SelectedIndex == (cmbID.Items.Count - 1))
{
cmbID.SelectedIndex =1;
}else
{
cmbID.SelectedIndex += 1;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.