This does half of what you want; it allows you to click on any column in
the row to select, but still just highlights the first item. It's a start,
void CAsciiListCtrl::OnClick(NMHDR* pNMHDR, LRESULT* pResult)
// Get the current mouse location and convert it to client
DWORD dwPos = GetMessagePos();
CPoint pt(LOWORD(dwPos), HIWORD(dwPos));
// Get indexes of the first and last visible items in listview
int nIndex = GetTopIndex();
int nLast = nIndex + GetCountPerPage();
nLast = (nLast > GetItemCount() ? GetItemCount() : nLast);
// Loop until number visible items has been reached.
while (nIndex <= nLast)
// Get the bounding rectangle of an item. If the mouse
// location is within the bounding rectangle of the item,
// you know you have found the item that was being clicked.
GetItemRect(nIndex, &rect, LVIR_BOUNDS);
UINT nFlags = LVIS_SELECTED | LVIS_FOCUSED;
SetItemState(nIndex, nFlags, nFlags);
// Get the next item in listview control.
*pResult = 0;
> Dear VC++ Experts,
> Is there anyone who can tell me how to highlight the selected
> item on CListCtrl ?
> I have created a list containing several columns. When I
> click a first column of list it gets highlighted but it
> doesn't get highlighted when I click second, third, fourth ... column
> of list. I want to highlight whole rows of list where ever I
> click, as long as the mouse position is on the same row.
> Please tell me how.
> Jae-Young Suh