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. listview item check problem

listview item check problem

Scheduled Pinned Locked Moved C#
helptutorialquestion
3 Posts 2 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
    numbers1thru9
    wrote on last edited by
    #1

    OK, im going to try and explain this the best I can. I have a listview that shows things by category with an associated treeview for displaying specific categories. I have the ItemCheck event handler changing categories whenever an item is checked and remove it from the listview. the problem is if the item is the last item in the listview when the box is checked/unchecked the program.cs throws an argument out or range exception. does anyone know why or how to fix it?

    A 1 Reply Last reply
    0
    • N numbers1thru9

      OK, im going to try and explain this the best I can. I have a listview that shows things by category with an associated treeview for displaying specific categories. I have the ItemCheck event handler changing categories whenever an item is checked and remove it from the listview. the problem is if the item is the last item in the listview when the box is checked/unchecked the program.cs throws an argument out or range exception. does anyone know why or how to fix it?

      A Offline
      A Offline
      albCode
      wrote on last edited by
      #2

      based on your words

      numbers1thru9 wrote:

      the problem is if the item is the last item in the listview when the box is checked/unchecked the program.cs throws an argument out or range exception. does anyone know why or how to fix it?

      can you show your code??


      "My advice to you is to get married. If you find a good wife, you will be happy; if not, you will become a philosopher." Socrates

      N 1 Reply Last reply
      0
      • A albCode

        based on your words

        numbers1thru9 wrote:

        the problem is if the item is the last item in the listview when the box is checked/unchecked the program.cs throws an argument out or range exception. does anyone know why or how to fix it?

        can you show your code??


        "My advice to you is to get married. If you find a good wife, you will be happy; if not, you will become a philosopher." Socrates

        N Offline
        N Offline
        numbers1thru9
        wrote on last edited by
        #3

        private void lvTasks_ItemCheck(object sender, ItemCheckEventArgs e) { if (lvTasks.Items[e.Index].Checked == false && lvTasks.Items[e.Index].SubItems[6].Text == "0") { //sql.makeCompleted(user_num, lvTasks.Items[e.Index].SubItems[4].Text); taskList.Remove(lvTasks.Items[e.Index]); lvTasks.Items[e.Index].SubItems[6].Text = "1"; lvTasks.Items[e.Index].SubItems.Add(DateTime.Today.Date.ToShortDateString()); completedTasks.Add(lvTasks.Items[e.Index]); lvTasks.Items.RemoveAt(e.Index); } else if (lvTasks.Items[e.Index].Checked == true && lvTasks.Items[e.Index].SubItems[6].Text == "1") { completedTasks.Remove(lvTasks.Items[e.Index]); lvTasks.Items[e.Index].SubItems[6].Text = "0"; lvTasks.Items[e.Index].SubItems[7].Text = ""; taskList.Add(lvTasks.Items[e.Index]); lvTasks.Items.RemoveAt(e.Index); }

        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