你点了按钮,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.
微软封装有相应的宏 直接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); } }
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.
直接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);
}
}