468,512 Members | 1,530 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

checkbox in CListCtrl

100 100+
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.

Expand|Select|Wrap|Line Numbers
  1. void SomeClass::OnCheckboxChanged
  2. ( NMHDR*                  pNMHeader,
  3.   LRESULT*                pResult )
  4. {
  5. func();
  6. }
  7. bool SomeClass::func
  8. (void)
  9. {
  10.   CListCtrl* a_pStatus = (CListCtrl*) GetDlgItem(IDC_DLG_FWUPDATE);
  11.     OC_ULong_t a_NoChecked=0;
  12.   for(OC_ULong_t  a_Index=0;a_Index<a_pStatus->GetItemCount() ;a_Index++)
  13.   {
  14.     // See if the check was selected
  15.     if(a_pStatus->GetItemState(a_Index,LVIS_STATEIMAGEMASK) == INDEXTOSTATEIMAGEMASK(2))
  16.     {
  17.             a_NoChecked++;
  18.             if(a_NoChecked>1)
  19.                 a_pStatus->SetCheck(a_Index,false);
  20.  
  21.     }
  22.   }
  23.     //if(a_NoChecked==1)
  24.     //  return true;
  25.             //else
  26.             //return false;
  27.   return true;
  28. }
  29.  
Jan 29 '08 #1
1 5797
Studlyami
464 Expert 256MB
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.
Jan 30 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Joseph Smith | last post: by
2 posts views Thread by Chandrakanth | last post: by
2 posts views Thread by Herbert VON GRÜNENWALD | last post: by
reply views Thread by Rajko | last post: by
reply views Thread by Victor | last post: by
reply views Thread by mike | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.