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 / C++ / MFC
  4. List control events

List control events

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
5 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.
  • J Offline
    J Offline
    jhorstkamp
    wrote on last edited by
    #1

    All, History: I have a list control that I used the onclick event to perform action with. The user wanted to be able to use the up/down arrows so I changed the event handler to use the itemchanged message. Now: The user wants to use both the mouse and the arrows - which is fine since the itemchanged message takes care of both of these actions. The problem being that the user also wants to be able to reperform (if that's a word) the same actions (it's a function to do a lot of number crunching on some data) on the currently selected item. The problem is that the itemchanged message gets called 3 times and thus the number crunching takes place 3 times! How do I get this to handle both mouse clicks and up/down arrows without having my function called 3 times? Thanks in advance, John

    M D 2 Replies Last reply
    0
    • J jhorstkamp

      All, History: I have a list control that I used the onclick event to perform action with. The user wanted to be able to use the up/down arrows so I changed the event handler to use the itemchanged message. Now: The user wants to use both the mouse and the arrows - which is fine since the itemchanged message takes care of both of these actions. The problem being that the user also wants to be able to reperform (if that's a word) the same actions (it's a function to do a lot of number crunching on some data) on the currently selected item. The problem is that the itemchanged message gets called 3 times and thus the number crunching takes place 3 times! How do I get this to handle both mouse clicks and up/down arrows without having my function called 3 times? Thanks in advance, John

      M Offline
      M Offline
      Monty2
      wrote on last edited by
      #2

      the function is called three times for the selected and the item that is being unselected(if thats a word :) ) so i am going by memory here it is called once when the previously selected item is Unselected, then for the new item that is selected and the the newly selected item gains focus rect examin the NM_LISTVIEW structure that is passed it contains the ItemNo and the Reason(selected, unselected etc) and then perform ur action Hope it helps :) C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg

      1 Reply Last reply
      0
      • J jhorstkamp

        All, History: I have a list control that I used the onclick event to perform action with. The user wanted to be able to use the up/down arrows so I changed the event handler to use the itemchanged message. Now: The user wants to use both the mouse and the arrows - which is fine since the itemchanged message takes care of both of these actions. The problem being that the user also wants to be able to reperform (if that's a word) the same actions (it's a function to do a lot of number crunching on some data) on the currently selected item. The problem is that the itemchanged message gets called 3 times and thus the number crunching takes place 3 times! How do I get this to handle both mouse clicks and up/down arrows without having my function called 3 times? Thanks in advance, John

        D Offline
        D Offline
        Diddy
        wrote on last edited by
        #3

        Like this (I think) void CYourDialog::OnClickList2(NMHDR* pNMHDR, LRESULT* pResult) { LPNMLISTVIEW pnmv = (LPNMLISTVIEW) pNMHDR; if(pnmv->uNewState & LVIS_SELECTED) { // do long running stuff } }

        J 1 Reply Last reply
        0
        • D Diddy

          Like this (I think) void CYourDialog::OnClickList2(NMHDR* pNMHDR, LRESULT* pResult) { LPNMLISTVIEW pnmv = (LPNMLISTVIEW) pNMHDR; if(pnmv->uNewState & LVIS_SELECTED) { // do long running stuff } }

          J Offline
          J Offline
          jhorstkamp
          wrote on last edited by
          #4

          Thanks - that almost works... It fails when I want to click on an already selected item and process data. (I'm varying some algorithm params in the dialog and observing the effect). So, I guess all I really want to do is to be able to use the up/down arrows to scroll and automatically process AND be able to use the mouse click to randomally select list data as well as process an already selected item. Is this the correct approach (using these events or do I need to set and clear some global bool that I create to bypass all these cascading events?) Thanks, John

          D 1 Reply Last reply
          0
          • J jhorstkamp

            Thanks - that almost works... It fails when I want to click on an already selected item and process data. (I'm varying some algorithm params in the dialog and observing the effect). So, I guess all I really want to do is to be able to use the up/down arrows to scroll and automatically process AND be able to use the mouse click to randomally select list data as well as process an already selected item. Is this the correct approach (using these events or do I need to set and clear some global bool that I create to bypass all these cascading events?) Thanks, John

            D Offline
            D Offline
            Diddy
            wrote on last edited by
            #5

            Yeah i don't think you get that event if you click on an already selected item... Have you tried processing NM_CLICK as well?

            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