如何从WTL中的ListViewCtrl多项选择中获取项目?

时间:2012-10-17 11:40:27

标签: visual-c++ listview wtl

我在 WTL 计划中有ListViewCtrl

我需要获取用户选择的项目(多项选择)。

我只能使用GetSelectedCount()来计算所选项目的数量。

GetSelectedItem()不适用于多项选择。

3 个答案:

答案 0 :(得分:2)

看看这里:

CListViewCtrl ListView = ...
for(INT nItem = ListView.GetNextItem(-1, LVNI_SELECTED); nItem >= 0; nItem = ListView.GetNextItem(nItem, LVNI_SELECTED))
{
  // Here you go with nItem
}

答案 1 :(得分:2)

现在这就是我做的方式:

for(int j=0;j<list.GetCount();j++)
{
    if(list.GetSel(j))
    {
        list.GetText(j,strTemp);
        doSomething(strTemp); //maybe put in an array
    }
}

答案 2 :(得分:1)

最短路:

int nItem = -1; 
while ( (nItem = m_lvList.GetNextItem(nItem, LVIS_SELECTED)) != -1 ) 
{ 
...
}
相关问题