Getting Selected List item
-
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 theiItem
is always -1. I'm sure it's pretty simple but I can't figure out what I'm missing. Any suggestions? Thanks, Paul -
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 theiItem
is always -1. I'm sure it's pretty simple but I can't figure out what I'm missing. Any suggestions? Thanks, PaulPaul - 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 } }
-
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 theiItem
is always -1. I'm sure it's pretty simple but I can't figure out what I'm missing. Any suggestions? Thanks, PaulMaybe 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: