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 = (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



Comments

  • hello

    Posted by tzjtzjtzj on 04/13/2013 10:41am

    good

    Reply
  • I want partly checkbox in one column

    Posted by Legacy on 03/29/2003 12:00am

    Originally posted by: sandmanq

    I am poor English, Sorry.
    
    I create listctrl with checkbox.
    checkbox is made full in one column.
    I want partly checkbox in one column.
    How?:)

    Reply
  • How to disable clicking checkboxes

    Posted by Legacy on 12/21/2001 12:00am

    Originally posted by: osl

    void CMyDlgClass::OnClickList(NMHDR* pNMHDR, LRESULT* pResult) 
    
    {
    NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
    m_nCurItem = pNMListView->iItem;
    UINT uFlags = 0;
    m_ListCtrl.HitTest(pNMListView->ptAction, &uFlags);
    if (uFlags == LVHT_ONITEMSTATEICON)
    {
    if (!m_ListCtrl.GetCheck(m_nCurItem)) m_ListCtrl.SetCheck(m_nCurItem);
    else m_ListCtrl.SetItemState(m_nCurItem, INDEXTOSTATEIMAGEMASK(1), LVIS_STATEIMAGEMASK);
    }

    *pResult = 0;
    }

    The same code in OnDblclkList function may be required.

    Reply
  • Another possibility

    Posted by Legacy on 12/05/2001 12:00am

    Originally posted by: Radu

    void MyClass::OnCheckBox1()
    
    {
    UpdateData(TRUE);
    if (IsDlgButtonChecked(1278))
    {
    CheckDlgButton(1278,BST_UNCHECKED);
    CheckDlgButton(1220,BST_CHECKED);
    }
    else
    {
    CheckDlgButton(1278,BST_CHECKED);
    CheckDlgButton(1220,BST_UNCHECKED);
    }
    }

    void MyClass::OnCheckBox2()
    {
    UpdateData(TRUE);
    if (IsDlgButtonChecked(1220))
    {
    CheckDlgButton(1278,BST_CHECKED);
    CheckDlgButton(1220,BST_UNCHECKED);
    }
    else
    {
    CheckDlgButton(1278,BST_UNCHECKED);
    CheckDlgButton(1220,BST_CHECKED);
    }

    }

    where OnCheckBox1,2 are member functions of the check box
    and 1278,1220 are the checkbox IDs.

    Reply
  • Ex(Properties)List

    Posted by Legacy on 10/07/2001 12:00am

    Originally posted by: Mike Philis

    Do you need an advanced list control? Check this out:
    
    http://www.exontrol.com/sg.jsp?content=products/exlist

    Mike
    www.exontrol.com

    Reply
  • How to disable clicking the CheckBox?

    Posted by Legacy on 05/15/2001 12:00am

    Originally posted by: Reichrath

    Good, but do you know how to disable clicking on the Checkbox?
    

    • Change picture index connected with this item to 0

      Posted by SzadQ on 06/01/2004 12:10pm

      Change picture index connected with this item to 0

      Reply
    Reply
  • Checkbox control in a ListCtrl?

    Posted by Legacy on 08/24/2000 12:00am

    Originally posted by: William Wacholtz

    Is it possible to disable a single row in a listctrl that has a checkbox checked? If it is, how?

    Reply
  • SetCheck?

    Posted by Legacy on 04/10/1999 12:00am

    Originally posted by: Andrei Korobkov

    SetCheck function is not a member of CListCtrl...

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Today's agile organizations pose operations teams with a tremendous challenge: to deploy new releases to production immediately after development and testing is completed. To ensure that applications are deployed successfully, an automatic and transparent process is required. We refer to this process as Zero Touch Deployment™. This white paper reviews two approaches to Zero Touch Deployment--a script-based solution and a release automation platform. The article discusses how each can solve the key …

  • The hard facts on SaaS adoption in over 80,000 enterprises: Public vs. private companies Mid-market vs. large enterprise GoogleApps, Office365, Salesforce & more Why security is a growing concern Fill out the form to download the full cloud adoption report.

Most Popular Programming Stories

More for Developers

RSS Feeds