0

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.

Rohit Vipin Mathews
  • 11,629
  • 15
  • 57
  • 112

3 Answers3

2

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
}
Roman R.
  • 68,205
  • 6
  • 94
  • 158
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
    }
}
cjamesm
  • 109
  • 7
1

shortest way:

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