This listbox is a control on another dialog.
ListBox Definition:
LISTBOX IDC_LNGNAMEBOX,205,21,190,131,WS_VSCROLL | WS_HSCROLL |
ES_AUTOHSCROLL | WS_TABSTOP | LBS_NOTIFY | LBS_NOINTEGRALHEIGHT | LBS_MULTIPLESEL
DataExchange:
CListBox m_LngNameList;
DDX_Control(pDX, IDC_LNGNAMEBOX, m_LngNameList);
MessageMap:
ON_LBN_SELCHANGE(IDC_LNGNAMEBOX, OnSelChangedLNGBox)
ON_LBN_DBLCLK(IDC_LNGNAMEBOX, OnMouseDBClick)
Scenario:
In a multiple selection listbox, when we click on any selected item, the selection goes of. I want to make the selection to stay always once the user clicks it (atleast any one item selected always).
Mysolution:
Whenever the selection changes if the item is already selected then select it again. I have done this is the "OnSelChangedLNGBOX" function.
Problem:
ON_LBN_SELCHANGE is called when we click an item and release the mouse (OnMouseUp). So the problem is when user clicks on item and holds it, the item is unselected and i am selecting back it again in OnSelChangedLNGBox. This is annoying, it looks like item is flickering, and also it doesn't seem to be consistent with windows. In windows if you open any folder with many documents if you click on an already selected document on mouse down the document still stays selected, but my item is unselected.
Question?
How can i solve this? I am trying to capture the PreTranslateMessage
if (pMsg->message == WM_LBUTTONDOWN)
{
SelectedItem = m_LngNameList.GetAnchorIndex();
}
But here selected item is not the correct one, it is not the same as the one i am getting in ON_LBN_SELCHANGE. Help please?