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. Getting Selected List item

Getting Selected List item

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
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.
  • M Offline
    M Offline
    masnu
    wrote on last edited by
    #1

    I'm trying to get the selected item from a CListCtrl. I intercept the NM_CLICK messge and try the following: NMITEMACTIVATE* pNMItem = (NMITEMACTIVATE*)pNMHDR; int nItem = pItem->iItem; int nSubItem = pItem->iSubItem; I get the subitem no problem but the iItem is always -1. I'm sure it's pretty simple but I can't figure out what I'm missing. Any suggestions? Thanks, Paul

    M M 2 Replies Last reply
    0
    • M masnu

      I'm trying to get the selected item from a CListCtrl. I intercept the NM_CLICK messge and try the following: NMITEMACTIVATE* pNMItem = (NMITEMACTIVATE*)pNMHDR; int nItem = pItem->iItem; int nSubItem = pItem->iSubItem; I get the subitem no problem but the iItem is always -1. I'm sure it's pretty simple but I can't figure out what I'm missing. Any suggestions? Thanks, Paul

      M Offline
      M Offline
      Member 260880
      wrote on last edited by
      #2

      Paul - Try using the GetFirstSelectedItemPosition method for CListCtrl. This returns a POSITION which is used in the next call to GetNextSelectedItem (that will return and item number). Then use the item number in the call to GetItem (you need to send in a pointer to an LVITEM structure). Here's some sample code... Hope this helps, Tim :laugh: CListCtrl myList; POSITION pos = mylist.GetFirstSelectedItemPosition(); while (NULL != pos) { int nItem = mylist.GetNextSelectedItem(pos); LVITEM lvItem; ZeroMemory ( &lvItem, sizeof(LVITEM) ); lvItem.mask = LVIF_IMAGE | LVIF_TEXT; //gets the information you are interest in lvItem.iItem = nItem; if (TRUE == mylist.GetItem(&lvItem)) { break; //if you want to stop } }

      1 Reply Last reply
      0
      • M masnu

        I'm trying to get the selected item from a CListCtrl. I intercept the NM_CLICK messge and try the following: NMITEMACTIVATE* pNMItem = (NMITEMACTIVATE*)pNMHDR; int nItem = pItem->iItem; int nSubItem = pItem->iSubItem; I get the subitem no problem but the iItem is always -1. I'm sure it's pretty simple but I can't figure out what I'm missing. Any suggestions? Thanks, Paul

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        Maybe this will help a bit...from the docs: "The iItem member of lpnmitem is only valid if the icon or first-column label has been clicked. To determine which item is selected when a click takes place elsewhere in a row, send an LVM_SUBITEMHITTEST message." Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        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