How to get items from a ListViewCtrl multiple selection in WTL?

半腔热情 提交于 2019-12-13 05:35:43

问题


I have a ListViewCtrl in a WTL program.

I need to get the items selected by the user(multiple selection).

I can only het the count of selected items using GetSelectedCount().

GetSelectedItem() doesnt work with multiple selection.


回答1:


Have a look here:

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



回答2:


Now this is just the way that I did it:

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



回答3:


shortest way:

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


来源:https://stackoverflow.com/questions/12933477/how-to-get-items-from-a-listviewctrl-multiple-selection-in-wtl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!