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: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Live Event Date: October 23, 2014 @ 12:00 p.m. ET / 9:00 a.m. PT Despite the current "virtualize everything" mentality, there are advantages to utilizing physical hardware for certain tasks. This is especially true for backups. In many cases, it is clearly in an organization's best interest to make use of physical, purpose-built backup appliances rather than relying on virtual backup software (VBA - Virtual Backup Appliances). Join us for this eSeminar to learn why physical appliances are preferable to …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds