본문 바로가기

프로그래밍/MFC

리스트 컨트롤 체크박스 관리하기

//선택 삭제하기
 int nCount=m_ctrIPList.GetItemCount();
 for(int i = nCount-1 ;i>=0;i--)
 {
  BOOL a= m_ctrIPList.GetCheck(i);
  if(a==TRUE)
  {
   CString tmp = m_ctrIPList.GetItemText(i,0);
   tmp.Format("%s 를 정막 삭제 하시겠습니까?",tmp);
   if(AfxMessageBox(tmp,MB_OKCANCEL)==IDOK)
   {
    m_ctrIPList.DeleteItem(i);
   }
  }
 }

//셀렉트 All 구현
 int nCount=m_ctrIPList.GetItemCount();
 for(int i = 0 ;i<nCount;i++)
 {
  m_ctrIPList.SetCheck(i);

 }
//clear All 구현
//헤더 인클루드 밑에 이거 넣고
#ifndef ListView_SetCheckState
#define ListView_SetCheckState(hwndLV, i, fCheck) \
ListView_SetItemState(hwndLV, i, \
INDEXTOSTATEIMAGEMASK((fCheck)+1), LVIS_STATEIMAGEMASK)
#endif

//소스는 이렇게...
 CListCtrl * tmp;
 tmp=&m_ctrIPList;
 int nCount=m_ctrIPList.GetItemCount();
 
 for(int i = 0 ;i<nCount;i++)
 {
  ListView_SetCheckState(tmp->GetSafeHwnd(),i,FALSE)
 }


별거 아닌데.. 책에 안나와있네..ㅠㅠ;