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. CListCtrl OnItemchanged, loops 3 times??

CListCtrl OnItemchanged, loops 3 times??

Scheduled Pinned Locked Moved C / C++ / MFC
questiontestingbeta-testinghelp
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.
  • V Offline
    V Offline
    Vickie
    wrote on last edited by
    #1

    Dear all, I am encountering a problem in calling this CListCtrl function, OnItemchanged. Whenever there is a change in selection, this functions will run 3 times!!! And, for the first time, the string got is " ", but at the second time, it shows the right string, then it is " " again for the third time. Can I know how does it happen for running 3 times? This is just a testing code. Actually I want to call another function whenever a selection is moved to another one, how can I do this if this function cannot work? void CTable::OnItemchangedtable(NMHDR* pNMHDR, LRESULT* pResult) { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; POSITION pos = m_table.GetFirstSelectedItemPosition(); int i = m_table.GetNextSelectedItem( pos ); CString cs = m_table.GetItemText(i, 0); AfxMessageBox( cs); *pResult = 0; } Thank you very much !!! Regards, Vickie

    L C 2 Replies Last reply
    0
    • V Vickie

      Dear all, I am encountering a problem in calling this CListCtrl function, OnItemchanged. Whenever there is a change in selection, this functions will run 3 times!!! And, for the first time, the string got is " ", but at the second time, it shows the right string, then it is " " again for the third time. Can I know how does it happen for running 3 times? This is just a testing code. Actually I want to call another function whenever a selection is moved to another one, how can I do this if this function cannot work? void CTable::OnItemchangedtable(NMHDR* pNMHDR, LRESULT* pResult) { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; POSITION pos = m_table.GetFirstSelectedItemPosition(); int i = m_table.GetNextSelectedItem( pos ); CString cs = m_table.GetItemText(i, 0); AfxMessageBox( cs); *pResult = 0; } Thank you very much !!! Regards, Vickie

      L Offline
      L Offline
      l a u r e n
      wrote on last edited by
      #2

      why dont u use the NM_CLICK message instead? --- "every year we invent better idiot proof systems and every year they invent better idiots"

      V 1 Reply Last reply
      0
      • L l a u r e n

        why dont u use the NM_CLICK message instead? --- "every year we invent better idiot proof systems and every year they invent better idiots"

        V Offline
        V Offline
        Vickie
        wrote on last edited by
        #3

        Since my tools is for the Blind, can't use Mouse but only keyboard, i.e. up, down arrow or short-cut key instead.

        1 Reply Last reply
        0
        • V Vickie

          Dear all, I am encountering a problem in calling this CListCtrl function, OnItemchanged. Whenever there is a change in selection, this functions will run 3 times!!! And, for the first time, the string got is " ", but at the second time, it shows the right string, then it is " " again for the third time. Can I know how does it happen for running 3 times? This is just a testing code. Actually I want to call another function whenever a selection is moved to another one, how can I do this if this function cannot work? void CTable::OnItemchangedtable(NMHDR* pNMHDR, LRESULT* pResult) { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; POSITION pos = m_table.GetFirstSelectedItemPosition(); int i = m_table.GetNextSelectedItem( pos ); CString cs = m_table.GetItemText(i, 0); AfxMessageBox( cs); *pResult = 0; } Thank you very much !!! Regards, Vickie

          C Offline
          C Offline
          Chris Meech
          wrote on last edited by
          #4

          I can't remember why there are 3 calls, but the first is to indicate that an item state is changing, selection state is being removed and the third is to indicate that an item state is changing, selection state is being set. I'm guessing that the second call is to provide access to the string and possibly change it prior to it being selected. Check further and I think you will find that the item for the first call is not the same item as the item for the subsequent second and third call. Add the pNMListView pointer to the watch window and look at each of the member variables change for each of the three calls to the method. That might aid in your understanding of what is happening.

          V 1 Reply Last reply
          0
          • C Chris Meech

            I can't remember why there are 3 calls, but the first is to indicate that an item state is changing, selection state is being removed and the third is to indicate that an item state is changing, selection state is being set. I'm guessing that the second call is to provide access to the string and possibly change it prior to it being selected. Check further and I think you will find that the item for the first call is not the same item as the item for the subsequent second and third call. Add the pNMListView pointer to the watch window and look at each of the member variables change for each of the three calls to the method. That might aid in your understanding of what is happening.

            V Offline
            V Offline
            Vickie
            wrote on last edited by
            #5

            Thank you very much!! I got how to do it now. It is to check the status of pNMListView->uNewState and pNMListView->uOldState before operation as follow: void CTable::OnItemchangedtable(NMHDR* pNMHDR, LRESULT* pResult) { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; UINT u = pNMListView->uNewState; UINT n = pNMListView->uOldState; if( u != 0 && n == 0 ) { POSITION pos = m_table.GetFirstSelectedItemPosition(); int i = m_table.GetNextSelectedItem( pos ); CString cs = m_table.GetItemText(i, 0); AfxMessageBox( cs); } *pResult = 0; }

            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