| | | | Browse by category |
Problem
When using the CGXCheckListComboBox class, currently I have to click on the actual checkbox to toggle the value. How can I change the behavior so the checkbox is checked/unchecked whenever I click anywhere on the item?
Cause
Action
In order to do this, you should derive a class from CGXCheckListComboLBox (which itself derives from the MFC class CCheckListBox). In your subclass, you can process the WM_LBUTTONDOWN message as shown below. You will also have to subclass CGXCheckListComboBox class and override the CreateListBox member. There you should instantiate your CGXCheckListComboLBox derivative.
Example:
void CYourCheckListComboLBox::OnLButtonDown(UINT nFlags, CPoint point) { |
|||||
m_bLButtonDown = TRUE; m_nOldSel = GetCurSel(); SetFocus(); // determine where the click is // if the item is disabled, then eat the click |
|||||
return; | |||||
if (m_nStyle != BS_CHECKBOX && m_nStyle != BS_3STATE) { |
|||||
// toggle check mark automatically if check mark was hit if (TRUE) //This was if(bInCheck) in the base class { |
|||||
CWnd* pParent = GetParent(); ASSERT_VALID(pParent); int nModulo = (m_nStyle == BS_AUTO3STATE) ? 3 : 2; int nCheck = GetCheck(nIndex); // Inform of check |
|||||
MAKEWPARAM(GetDlgCtrlID(), CLBN_CHKCHANGE), (LPARAM)m_hWnd); |
|||||
return; | |||||
} | |||||
}
// do default listbox selection logic |
|||||
} |