Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

C#
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;

                               }
}


I am getting error as:

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

Thanks.
Posted
Updated 20-Nov-15 8:43am
v2

1 solution

The second if statement does not make any sense, so just remove it.

Then you will advance on each click on btnaccept button.
 
Share this answer
 
Comments
Member 12076824 20-Nov-15 13:56pm    
Thanks I should have used else instead, as I have button needs to be enabled and image to be cleared.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900