Re: CListCtrl Checkboxes
To add to what others have said I'd use:
ON_NOTIFY(NM_CLICK, IDC_LIST, &CMyDlg::OnNMClickList)
Here is some sample code... I am using a virtual list so I am changing the
data that is being used for the list. I also like to handle more than one
item if more than one selected. This routine toggles the current settings.
Tom
// Check or uncheck item. If more than one item is selected then use the
one from the
// hit test to determine how we are setting the others (I.E., if it is off
we turn the other
// selected ones on).
void CMyDlg::OnNMClickList(NMHDR *pNMHDR, LRESULT *pResult)
{
NMLISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
LVHITTESTINFO hitinfo;
*pResult = 0;
//Copy click point
hitinfo.pt = pNMListView->ptAction;
//Make the hit test...
int nItem = m_cList.HitTest(&hitinfo);
if(hitinfo.flags != LVHT_ONITEMSTATEICON)
return; // Didn't click on an icon
if(m_cList.GetItemState(nItem,LVIS_SELECTED) != LVIS_SELECTED) {
// They clicked on one that is not selected... just change it
CMyDataInfo *pItem = (CMyDataInfo *)m_pMyDataArray->GetAt(nItem);
pItem->m_bChecked = !pItem->m_bChecked;
m_cList.Invalidate();
*pResult = 1;
return;
}
if(nItem != -1) {
if(m_pMyDataArray == NULL)
return;
// Get the checked state from the one they clicked on
CMyDataInfo *pItem = (CMyDataInfo *)m_pMyDataArray->GetAt(nItem);
BOOL bChecked = !pItem->m_bChecked;
UINT uSelectedCount = m_cList.GetSelectedCount();
// Update all of the selected items.
if (uSelectedCount > 0) {
nItem = -1;
m_cList.SetRedraw(false);
for (UINT i=0;i < uSelectedCount;i++) {
nItem = m_cList.GetNextItem(nItem, LVNI_SELECTED);
pItem = (CMyDataInfo *)m_pMyDataArray->GetAt(nItem);
pItem->m_bChecked = bChecked;
}
*pResult = 1;
m_cList.Invalidate();
m_cList.SetRedraw();
}
}
}
"Ian Semmel" <isemmelNOJUNK@NOKUNKrocketcomp.com.au> wrote in message
news:eILW0t8VJHA.4888@TK2MSFTNGP02.phx.gbl...
What message is generated when a checkbox item in a CListCtrl is clicked
or how do I trap it.