I have a comboBox with a checkbox inside for each value.
When i change the selectedIndex of CustomerCBC.CheckBoxItems[1], he loop trought the customerCBC.Items.
The error occurs when the last item in the comboBox need to change.
Error:Collection was modified; enumeration operation may not execute.
For the comboBox i use the PresentationControls.CheckBoxComboBox control.
Already tried to 'Lock the items in the combobox'
If you need more info, feel free to ask.
private void CheckComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
int countChecked = 2;
if (customerCBC.Items.Count > 2)
{
if (customerCBC.CheckBoxItems[1].Checked == true)
{
foreach (Object dr in customerCBC.Items)
{
if (customerCBC.Items.IndexOf(dr) > 1){
//Set all the customers checked
customerCBC.CheckBoxItems[countChecked].Checked = true;
countChecked++;
}
}
}
else
{
try
{
foreach (Object dr in customerCBC.Items)
{
if (customerCBC.Items.IndexOf(dr) > 1)
{
//Set all the customers unchecked
customerCBC.CheckBoxItems[countChecked].Checked = false;
// MessageBox.Show(countChecked.ToString());
countChecked++;
}
}
}
catch (Exception e1)
{
//MessageBox.Show(countChecked.ToString());
MessageBox.Show(e1.Message);
}
}