Click to See Complete Forum and Search --> : Detecting which subitem has been clicked in a listcontrol


blep
May 21st, 1999, 08:54 AM
I'm using VC++ 5.0, and I need to detect which subitem has been clicked in a list control. The method HitTest() only returns the item. A Method would be to test in which subitem range the click fall into but there is no way to get the listctrl position (GetOrigin() does not work in report mode).

So how do you detect the subitem on which the user click ?

May 21st, 1999, 09:33 AM
A solution that works in alone or multiple selection mode:

int length = m_list.GetItemCount();

for (int i = 0; i < length;i++) {
if (m_list.GetItemState(i, LVIS_SELECTED)) {
// do what you want with the selected line
// use the index i for access to the object
// example: m_list.GetItemText( i, 0, szDest, 16 );
}
}

There is another solution for the one-select mode, but I've forgotten it. This one works well.

Pascal.

May 21st, 1999, 09:53 AM
when you catch the OnClick event, you get a NMHDR* var as one of your parameters, you can cast this to a NM_LISTVIEW*, and it has an iSubItem member that should tell you which subitem was clicked (I think).

something like

void
CMyListCtl::OnClick (NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
int iSubItem = pNMListView->iSubItem;
}




--michael

BarD
May 21st, 1999, 09:54 AM
Hello!
You can use method CListCtrl::SubItemHitTest() if you are using comctl32.dll version >= 4.70 (it comes with IE3.0). See MSDN for details.
Dmitry Barashev.