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

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • VMware vCloud® Government Service provided by Carpathia® is an enterprise-class hybrid cloud service that delivers the tried and tested VMware capabilities widely used by government organizations today, with the added security and compliance assurance of FedRAMP authorization. The hybrid cloud is becoming more and more prevalent – in fact, nearly three-fourths of large enterprises expect to have hybrid deployments by 2015, according to a recent Gartner analyst report. Learn about the benefits of …

Most Popular Programming Stories

More for Developers

RSS Feeds