我有一个对话框,上面有一个ListCtrl,加了LVS_EX_CHECKBOXES属性。
我想在一个ITEM Check后,让其他的Item变为不打勾。
请问该如何处理,处理什么消息呢?
谢谢!

解决方案 »

  1.   

    CListCtrl  m_List;
    for(i=0,i<m_List.GetItemCount();i++
    {
      m_List.SetCheck(i,FALSE);
    }POSITION pos =m_ListView.GetFirstSelectedItemPosition();
    int intIndex=m_ListView.GetNextSelectedItem(pos);
    if(intIndex<=0)intIndex=0;
    m_List.SetCheck(intIndex,FALSE);
      

  2.   

    ListView_SetItemState(hwnd, -1, INDEXTOSTATEIMAGEMASK(FALSE?2:1), LVIS_STATEIMAGEMASK );ListView_SetItemState(hwnd, iItem, INDEXTOSTATEIMAGEMASK(bChecked?2:1), LVIS_STATEIMAGEMASK );
      

  3.   

    多谢。
    再问在NM_CLICK消息中如何知道当前选中的是第几个,还有,如何让LISTCTRL只能选择一个而不是多个?
    谢谢!
      

  4.   

    NM_CLICK (list view)
    Sent by a list-view control when the user clicks an item with the left mouse button. This notification message is sent in the form of a WM_NOTIFY message. NM_CLICK
        lpnmitem = (LPNMITEMACTIVATE) lParam;Parameters
    lpnmitem 
    Version 4.71. Address of an NMITEMACTIVATE structure that contains additional information about this notification message. The iItem, iSubItem, and ptAction members of this structure contain information about the item. 
    Return Values
    The return value for this notification is not used. Res
    This notification is identical to the standard NM_CLICK notification except that in version 4.71 and later, the list view supplies an NMITEMACTIVATE structure instead of an NMHDR structure for the lParam. The iItem member of lpnmitem will only be valid if the icon or first-column label has been clicked. To determine which item is selected when a click takes place elsewhere in a row, send an LVM_SUBITEMHITTEST message. 
      

  5.   

    LVS_SINGLESEL   Allows only one item at a time to be selected. By default, multiple items can be selected.
      

  6.   

    CListCtrl  m_List;
    m_List.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_SINGLESEL );
    //只能选择一个而不是多个
    POSITION pos =m_ListView.GetFirstSelectedItemPosition();
    int intIndex=m_ListView.GetNextSelectedItem(pos);
    //intIndex的 值 就 是 当前选中的是第几个