如题,请问如何删除listbox选中的多行记录,同时如何设置ctrl+A键来全选记录?

解决方案 »

  1.   

    CListBox::GetSelItems 
    int GetSelItems( int nMaxItems, LPINT rgIndex ) const;Return ValueThe actual number of items placed in the buffer. If the list box is a single-selection list box, the return value is LB_ERR.CListBox::SelItemRange 
    int SelItemRange( BOOL bSelect, int nFirstItem, int nLastItem );
      

  2.   


    int nCount = m_list.GetSelectedCount();
    int* buf = new int[nCount];
    memset(buf, -1, sizeof(int)*nCount); int nIndex = 0;
    POSITION pos = m_list.GetFirstSelectedItemPosition();
    while(pos)
    {
    int nTmp = m_list.GetNextSelectedItem(pos);
    buf[nIndex++] = nTmp;
    } for(int i=nIndex-1; i>=0; i--)
    {
    m_list.DeleteItem(buf[i]);
    } delete[] buf;
      

  3.   


    // 删除所选的项
    int nCount = m_listBox.GetSelCount();
    int* buffer = new int[nCount];
    memset(buffer, -1, sizeof(int)*nCount); m_listBox.GetSelItems(nCount, buffer); for(int i=nCount-1; i>=0; i--)
    {
    m_listBox.DeleteString(buffer[i]);
    }
    delete[] buffer;// Ctrl+A选择所有的Item,也可以注册系统Hotkey
    BOOL CXXDlg::PreTranslateMessage(MSG* pMsg) 
    {
    // TODO: Add your specialized code here and/or call the base class
    if(WM_KEYDOWN == pMsg->message && _T('A') == pMsg->wParam)
    {
    if(HIBYTE(GetKeyState(VK_CONTROL)))
    {
    m_listBox.SelItemRange(TRUE, 0, m_listBox.GetCount());
    }
    }
    return CDialog::PreTranslateMessage(pMsg);
    }