how to check
-
Hi folks, some items in checkedlistbox for example the item will be like this (Kishore) kishore@gmail.com i had a string kishore@gmail.com i have to compare this string with the item in checkedlistbox i have completed this but iam getting a error "List that this enumerator is bound to has been modified. An enumerator can only be used if the list does not change." Code: if (checkedListBox_MailLst.Items.Count > 0) foreach (string item in checkedListBox_MailLst.Items) { string mailItem=item; checklistItem = mailItem.Split(' '); foreach (string mailId in myMail) { if (checklistItem[2].ToString() == mailId) if(checkedListBox_MailLst.Items.Contains (mailItem)) { int selectedItemIndex = checkedListBox_MailLst.Items.IndexOf(mailItem); checkedListBox_MailLst.SetItemCheckState(selectedItemIndex, CheckState.Checked); } } }
-
Hi folks, some items in checkedlistbox for example the item will be like this (Kishore) kishore@gmail.com i had a string kishore@gmail.com i have to compare this string with the item in checkedlistbox i have completed this but iam getting a error "List that this enumerator is bound to has been modified. An enumerator can only be used if the list does not change." Code: if (checkedListBox_MailLst.Items.Count > 0) foreach (string item in checkedListBox_MailLst.Items) { string mailItem=item; checklistItem = mailItem.Split(' '); foreach (string mailId in myMail) { if (checklistItem[2].ToString() == mailId) if(checkedListBox_MailLst.Items.Contains (mailItem)) { int selectedItemIndex = checkedListBox_MailLst.Items.IndexOf(mailItem); checkedListBox_MailLst.SetItemCheckState(selectedItemIndex, CheckState.Checked); } } }
You can't modify what you're enumerating over. If you think about it, and the possible disasterous results if you could, it makes sense!. What you can do is flag or store whatever needs modifying, and do the change afterwards. If you no longer need to keep testing, you can use break to exit imediately.
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus) -
Hi folks, some items in checkedlistbox for example the item will be like this (Kishore) kishore@gmail.com i had a string kishore@gmail.com i have to compare this string with the item in checkedlistbox i have completed this but iam getting a error "List that this enumerator is bound to has been modified. An enumerator can only be used if the list does not change." Code: if (checkedListBox_MailLst.Items.Count > 0) foreach (string item in checkedListBox_MailLst.Items) { string mailItem=item; checklistItem = mailItem.Split(' '); foreach (string mailId in myMail) { if (checklistItem[2].ToString() == mailId) if(checkedListBox_MailLst.Items.Contains (mailItem)) { int selectedItemIndex = checkedListBox_MailLst.Items.IndexOf(mailItem); checkedListBox_MailLst.SetItemCheckState(selectedItemIndex, CheckState.Checked); } } }
0. Remove the email address from your example unless you really *like* special devices for the decerning gentleman. 1. Compare strings using
string1.Equals(string2)
,string1 == string2
is just comparing that the objects are the same (the same reference) not that the contents are the same.
Panic, Chaos, Destruction. My work here is done.