OK, I want to just add the resource, fill it with data, and then click on it anywhere on the line then return nIndex (which row). I can fill it, but I cant get where it was clicked on or handle the whole line
Printable View
OK, I want to just add the resource, fill it with data, and then click on it anywhere on the line then return nIndex (which row). I can fill it, but I cant get where it was clicked on or handle the whole line
int i, count = m_ctrlyourlist.GetItemCount();
CString somevalue;
for ( i=0; i < count; i++ )
if ( m_ctrlyourlist.GetItemState( i, LVIS_SELECTED ) )
{
// get the data out of first column
somevalue=m_ctrlyourlist.GetItemText( i,0);
}
You can use the HitTest() method of CListCtrl.
You will need to decide when you want to do the action. It can be on a button click, or on a click in the list control (catch NM_CLICK), or when an item changes (LVN_ITEMCHANGED).
Then in the code you can use GetNextItem to iterate through the list.int nSelItem = -1;
while ( -1 != ( nSelItem = m_list.GetNextItem(nSelItem, LVNI_SELECTED) ) )
{
// Do stuff
}
1.subclass clistview
2.Track lbuttondown message
3.use CListCtrl HitTest function to get list item id
In NM_CLICK use
SubItemHitTest(LPLVHITTESTINFO HitInfo)
This will return the iItem and iSubItem (in HitInfo structure). You also get the info whether the click was made on the item icon or item label or above or below or to the left or to the right of the client area of the list control.
If click is made on the item,
iItem = Item index and
iSubItem = 0
If the click is made on the subitem
iItem = SubItem's parent item
iSubItem = SubItem index