Click here to Skip to main content
15,885,703 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to get row and column of list control where I click when I clicked,
I use the following code,
isubitem value is okey , but iItem value is 0 when I click on first column and -1 when I click other columns ,
how Can I get other colomns value and what is wrong in my code?
Waiting for you.

What I have tried:

void MyView::OnNMClickList3(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
	int r = pNMItemActivate->iSubItem;
	int t = pNMItemActivate->iItem;
	*pResult = 0;
}
Posted
Updated 31-Jul-18 1:41am

1 solution

See the description of the NM\_CLICK (list view) notification code | Microsoft Docs[^]:
Quote:
The iItem member of lParam 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.

Add this to your code (untested):
if (t < 0)
{
    LVHITTESTINFO tHitTest;
    tHitTest.pt = pNMItemActivate->ptAction;
    // This assumes that MyView is the list view for which the message is processed.
    // If not, you have to send the message to the list using it's member variable
    //  or ::SendMessage passing it's HWND
    t = SendMessage(LVM_SUBITEMHITTEST, 0, reinterpret_cast<LPARAM>(&tHitTest));
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900