Click to See Complete Forum and Search --> : CListCtrl


August 30th, 1999, 03:36 AM
Hi,

I am trying to do the following: If the user clicks anywhere on a CListCtrl (doesn't have to be the first column), the matching item should be selected. For this action, I am using code I found on codeguru's control section.

Why isn't it working?

void CPreislisteDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default

CDialog::OnLButtonDown(nFlags, point);

int index;
point.x = 2;

if((index = m_cPreisListe.HitTest(point, NULL)) != -1)
{
MessageBox("OK");
m_cPreisListe.SetItemState(index, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
}
}



Thanks!


Fox20

Martin Speiser
August 30th, 1999, 04:43 AM
Hi,

OnLButtonDown gives you the coordinates in coordinates relative to the dialog, but HitTest expects them to be relative to the CListCtrl. So you need to convert them with MapWindowPoints.

But a better way will be to write a handler for the NM_CLICK message. It will give you not only the point where clicked, but also which item and subitem.


Martin