checkbox in CListCtrl

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rag84dec
    New Member
    • Mar 2007
    • 100

    checkbox in CListCtrl

    Hi,
    I have many check boxes in a list control.My problem is to uncheck the check box if there is a check box already checked.How can i do??..I tried doing the below but it checks the first check box and unchecks the others.

    Code:
    void SomeClass::OnCheckboxChanged
    ( NMHDR*                  pNMHeader,
      LRESULT*                pResult )
    {
    func();
    }
    bool SomeClass::func
    (void)
    {
      CListCtrl* a_pStatus = (CListCtrl*) GetDlgItem(IDC_DLG_FWUPDATE);
    	OC_ULong_t a_NoChecked=0;
      for(OC_ULong_t  a_Index=0;a_Index<a_pStatus->GetItemCount() ;a_Index++)
      {
        // See if the check was selected
        if(a_pStatus->GetItemState(a_Index,LVIS_STATEIMAGEMASK) == INDEXTOSTATEIMAGEMASK(2))
        {
    			a_NoChecked++;
    			if(a_NoChecked>1)
    				a_pStatus->SetCheck(a_Index,false);
    			
        }
      }
    	//if(a_NoChecked==1)
        //  return true;
    			//else
    			//return false;
      return true;
    }
  • Studlyami
    Recognized Expert Contributor
    • Sep 2007
    • 464

    #2
    Why are you manually handling the check boxes?

    when creating the CListCtrl Set the style of the list control to use checkboxes. If you want to do something manually when the list item gets checked call the base class for handling the checkbox then do what you want (or vise versa).

    If you want to handle the checkbox manually take a look at the default code and see what the difference is.

    Comment

    Working...