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: April 22, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Database professionals — whether developers or DBAs — can often save valuable time by learning to get the most from their new or existing productivity tools. Whether you're responsible for managing database projects, performing database health checks and reporting, analyzing code, or measuring software engineering metrics, it's likely you're not taking advantage of some of the lesser-known features of Toad from Dell. Attend this live …

  • Ever-increasing workloads and the challenge of containing costs leave companies conflicted by the need for increased processing capacity while limiting physical expansion. Migration to HP's new generation of increased-density rack-and-blade servers can address growing demands for compute capacity while reducing costly sprawl. Sponsored by: HP and Intel® Xeon® processors Intel, the Intel logo, and Xeon Inside are trademarks of Intel Corporation in the U.S. and/or other countries. HP is the sponsor …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds