Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. how to check

how to check

Scheduled Pinned Locked Moved C#
tutorialcomhelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nath
    wrote on last edited by
    #1

    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); } } }

    D N 2 Replies Last reply
    0
    • N Nath

      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); } } }

      D Offline
      D Offline
      DaveyM69
      wrote on last edited by
      #2

      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)

      1 Reply Last reply
      0
      • N Nath

        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); } } }

        N Offline
        N Offline
        Nagy Vilmos
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups