Add a WM_LBUTTONDOWN handler in the CListCtrl derived class.
Code for OnLButtonDown() is given below.
Before calling HitTest(), the x coordinate is changed to 2. This forces
the point being tested to fall on the first column. A value of x below
2 fails (it is presumably occupied by the border ).
Note that the call to the base class OnLButtonDown() precedes the call
to SetItemState.
This method fails if the first column is not visible. We can use the function
HitTestEx() described in an earlier section
to cover for the situation when the first column is not visible.
void CMyListCtrl::OnLButtonDown(UINT nFlags, CPoint point) { CListCtrl::OnLButtonDown(nFlags, point); int index; point.x = 2; if( ( index = HitTest( point, NULL )) != -1 ) { SetItemState( index, LVIS_SELECTED | LVIS_FOCUSED , LVIS_SELECTED | LVIS_FOCUSED); } }