C#组合框项目计数错误 [英] C# combobox item counts error

查看:96
本文介绍了C#组合框项目计数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用comboxbox并面临问题。



我在comboBox2中列出了75或50个文件,当selecetd索引达到第75或第50个文件时它会抛出错误。



当选中的索引到达combobox2的最后一个文件时,我试图更改comboBox1的选定索引。



I am working with comboxbox and facing issue.

I have 75 or 50 files listed in comboBox2, when selecetd index reaches 75th or 50th file it throws error.

I am trying to change selected index of comboBox1 when selected index reached last file of combobox2.

private void btnaccept_Click(object sender, System.EventArgs e)
{
if (comboBox2.SelectedIndex < comboBox2.Items.Count - 1)
                               {
                                  comboBox2.SelectedIndex = comboBox2.SelectedIndex + 1;
                               }

if (comboBox2.SelectedIndex > comboBox2.Items.Count -1)
                               {
                     comboBox1.SelectedIndex = comboBox1.SelectedIndex + 1;

                               }
}





我收到的错误是:



InvalidArgument = 75的值对于&#39; SelectedIndex无效

参数名称:SelectedIndex

任何帮助和建议表示赞赏。



谢谢。



I am getting error as:

InvalidArgument=Value of 75 is not valid for &#39;SelectedIndex
Parameter name: SelectedIndex
Any help and suggestions appreciated.

Thanks.

推荐答案

第二个 if 声明没有任何意义,所以只需将其删除即可。



然后,您将在每次点击 btnaccept 按钮时前进。
The second if statement does not make any sense, so just remove it.

Then you will advance on each click on btnaccept button.


这篇关于C#组合框项目计数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆