有一个ListView,旁边一个删除按钮,在点删除的时候需要获取到当前ListView选中项的索引,
用SendMessage怎么实现,我用 LVM_GETHOTITEM 返回总是1.
因为是用SDK写的,不知道除了SendMessage还有别的办法吗?

解决方案 »

  1.   

    你点了按钮,listview的焦点就没有了吧?你看看焦点是否还存在,选择的项目是否还在突出显示。如果焦点失去了,你可以在listView每次点击的时候,获取其选择的项目进行保存,然后等删除的时候即使失去焦点也可以找到当时用户的选择项
    ListView.getSelectedItems Retrieves an array containing all selected items in a list view control. Syntaxpublic ListItem[] getSelectedItems()Return ValueReturns an array of ListItem objects that represents all the currently selected items. In a single-selection list view control, returns an array containing a single element. If there are no selected items in the list view control, returns an empty array. 
      

  2.   

    微软封装有相应的宏
    直接SendMessage啰嗦一点
    其实你可以参看MFC的代码的
    vector<int> list;
    int i = -1;
    while(true)
    {
    i = ListView_GetNextItem(m_hListView, i, LVIS_SELECTED);
    if(i == -1)  //没有了
    {
    break;
    }
    else
    {
    list.push_back(i);
    }
    }