Re: CListCtrl.GetNextSelectedItem doesnot seem to work.
Hi PJ,
I typically just do a loop like the one inserted here. This is for deleting
files so it asks the user for confirmation first, but you'll get the idea.
void CMyView::OnDelete()
{
CString cs;
CFileInfo *pInfo;
int nNumberOfItems = GetSelectedCount();
if(nNumberOfItems == 0)
return; // Nothing selected
int nItem = GetNextItem(-1,LVNI_SELECTED);
if(AfxMessageBox(IDS_OKTOREMOVE,MB_YESNO|MB_ICONINFORMATION) == IDYES) {
do {
pInfo = (CFileInfo *)m_FileArray.GetAt(nItem);
delete pInfo;
m_FileArray.RemoveAt(nItem);
DeleteItem(nItem);
--nItem; // So we go back and get the last one. The queue
// is one fewer now
} while ((nItem = GetNextItem(nItem,LVNI_SELECTED)) >= 0);
}
}
Tom
"pj" <praneshrj@gmail.com> wrote in message
news:1172870196.485691.129750@z35g2000cwz.googlegroups.com...
Hi,
I am trying to use this code from msdn to get the list of selected
rows in the container of the CListCtrl (multi select mode). It works
fine if the user selects 2 rows. But for more that that, it doesnot
work. "pos" will point to NULL after two rows.
MSDN code:
=========
POSITION pos = pList->GetFirstSelectedItemPosition();
if (pos == NULL)
//TRACE0("No items were selected!\n");
else
{
while (pos)
{
int nItem = pList->GetNextSelectedItem(pos);
//TRACE1("Item %d was selected!\n", nItem);
// you could do your own processing on nItem here
}
}
Is this a bug or am I doing something wrong here.
Thanks,
-pj.