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. checked list view items

checked list view items

Scheduled Pinned Locked Moved C#
question
7 Posts 4 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

    i have a listview in my program and whenever the item is checked or unchecked i want certain things to happen. how can i accomplish this without the item checked event handler taking over every time i add an item to the listview?

    E E 2 Replies Last reply
    0
    • N numbers1thru9

      i have a listview in my program and whenever the item is checked or unchecked i want certain things to happen. how can i accomplish this without the item checked event handler taking over every time i add an item to the listview?

      E Offline
      E Offline
      Ed Poore
      wrote on last edited by
      #2

      numbers1thru9 wrote:

      i have a listview in my program and whenever the item is checked or unchecked i want certain things to happen. how can i accomplish this without the item checked event handler taking over every time i add an item to the listview?

      :wtf: Those statements contradict each other. Unless you mean that the CheckChanged or what ever it's called event is being fired when you add an item to the list view?


      Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9 Ed

      N 1 Reply Last reply
      0
      • E Ed Poore

        numbers1thru9 wrote:

        i have a listview in my program and whenever the item is checked or unchecked i want certain things to happen. how can i accomplish this without the item checked event handler taking over every time i add an item to the listview?

        :wtf: Those statements contradict each other. Unless you mean that the CheckChanged or what ever it's called event is being fired when you add an item to the list view?


        Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9 Ed

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

        ok say i have a list of items in the listview, when i either check or uncheck them i want certain things to happen. but if i add an item to the listview, it fires the event handler as if i checked or unchecked an existing item and i want to block it from doing that.

        E 1 Reply Last reply
        0
        • N numbers1thru9

          i have a listview in my program and whenever the item is checked or unchecked i want certain things to happen. how can i accomplish this without the item checked event handler taking over every time i add an item to the listview?

          E Offline
          E Offline
          Eric Dahlvang
          wrote on last edited by
          #4

          Put your code in the ItemCheck event handler, rather than ItemChecked. ItemCheck does not fire when an item is added.

          --EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters

          1 Reply Last reply
          0
          • N numbers1thru9

            ok say i have a list of items in the listview, when i either check or uncheck them i want certain things to happen. but if i add an item to the listview, it fires the event handler as if i checked or unchecked an existing item and i want to block it from doing that.

            E Offline
            E Offline
            Ed Poore
            wrote on last edited by
            #5

            How about when you add an item to the list view use the "Tag" property to indicate that it's just been added and thus ignore it later in the code:

            private void AddItemToList()
            {
             ListViewItem lvi = new ListViewItem("New Item");
             lvi.Tag = "ItemJustAdded";
             this.listView.Items.Add(lvi);
            }

            private void listView_ItemChecked(object sender, ItemCheckedEventArgs e)
            {
             if (e.Item.Tag == "ItemJustAdded")
              return;
             // Do normal check stuff here.
            }


            Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9 Ed

            D 1 Reply Last reply
            0
            • E Ed Poore

              How about when you add an item to the list view use the "Tag" property to indicate that it's just been added and thus ignore it later in the code:

              private void AddItemToList()
              {
               ListViewItem lvi = new ListViewItem("New Item");
               lvi.Tag = "ItemJustAdded";
               this.listView.Items.Add(lvi);
              }

              private void listView_ItemChecked(object sender, ItemCheckedEventArgs e)
              {
               if (e.Item.Tag == "ItemJustAdded")
                return;
               // Do normal check stuff here.
              }


              Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9 Ed

              D Offline
              D Offline
              Dan Neely
              wrote on last edited by
              #6

              Ed.Poore wrote:

              How about when you add an item to the list view use the "Tag" property to indicate that it's just been added and thus ignore it later in the code:

              You'dthen need to clear the tag either in the handler, or in the add method otherwise checks will be permanantly nonfunctional in new items.

              -- Rules of thumb should not be taken for the whole hand.

              E 1 Reply Last reply
              0
              • D Dan Neely

                Ed.Poore wrote:

                How about when you add an item to the list view use the "Tag" property to indicate that it's just been added and thus ignore it later in the code:

                You'dthen need to clear the tag either in the handler, or in the add method otherwise checks will be permanantly nonfunctional in new items.

                -- Rules of thumb should not be taken for the whole hand.

                E Offline
                E Offline
                Ed Poore
                wrote on last edited by
                #7

                That was left as an exercise to the reader ;P


                Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9 Ed

                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