To make check boxes act like radio buttons (mutually exclusive) | CodeGuru

To make check boxes act like radio buttons (mutually exclusive)

If you have a list control in your dialog with the LVS_EX_CHECKBOXES style, you can make the check boxes to act like radiobuttons by adding two lines of code.. First map the LVN_ITEMCHANGED event of the list control from the class wizard and add the code shown void CListDlg::OnItemchangedMylist(NMHDR* pNMHDR, LRESULT* pResult) { NM_LISTVIEW* pNMListView […]

Written By
CodeGuru Staff
CodeGuru Staff
Feb 1, 1999
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

If you have a list control in your dialog with the
LVS_EX_CHECKBOXES style, you can make the check boxes to act like
radiobuttons by adding two lines of code.. First map the
LVN_ITEMCHANGED event of the list control from the class wizard
and add the code shown

void CListDlg::OnItemchangedMylist(NMHDR* pNMHDR, LRESULT* pResult)
{
 NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
 /* If the event is not fired because of any change in individual items then the oldstate and
 newstate members of pNMListView are not used.  So check for that.*/
 if (!pNMListView->uOldState && !pNMListView->uNewState)
  return;
 // m_listctl is the member variable of the dialog which is of type CListCtl.
 BOOL bChecked = ListView_GetCheckState(m_listctl.m_hWnd, pNMListView->iItem);
 // if it’s checked uncheck everything else.
 int nCount;
 if (bChecked)
  for(nCount=0;nCount<m_listctl.GetItemCount();nCount++)
   if(nCount != pNMListView->iItem)
    m_listctl.SetCheck(nCount, FALSE);
}

Date Last Update: February 1, 1999

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.