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: September 10, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild". This loop of continuous delivery and continuous feedback is …

  • Java developers know that testing code changes can be a huge pain, and waiting for an application to redeploy after a code fix can take an eternity. Wouldn't it be great if you could see your code changes immediately, fine-tune, debug, explore and deploy code without waiting for ages? In this white paper, find out how that's possible with a Java plugin that drastically changes the way you develop, test and run Java applications. Discover the advantages of this plugin, and the changes you can expect to see …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds