Q: What did the fish say when he hit a solid concrete wall?
A: "DAM"!!
Well I just hit another solid concrete wall, and I too am saying "DAMN"!! I
am developing an MFC Doc/View app which utilizes a CListCtrl to present a
list of items to the user. I want to give the user the ability to select
multiple items and delete them. My problem is that when I iterate through
the selected items from the top, and delete them (as shown in the loop
structure below), items get skipped over because their indices change when
an item is deleted.
// Begin code snippet
CListCtrl m_wndList;
...
...
POSITION posItem = m_wndList.GetFirstSelectedItemPosition();
while (posItem)
{
int nIndex = m_wndList.GetNextSelectedItem(posItem);
m_wndList.DeleteItem(nIndex);
}
// End code snippet
It seems like if I could iterate backwards, the problem would go away
because any previous index would be unaffected by DeleteItem(). If I could
start with the LAST selected item position and iterate with a get PREVIOUS
selected item method, then it would work fine. I have searched the
documentation, and I don't see any CListCtrl members that can facilitate
this. But certainly there must be a way to effectively accomplish this,
such as when one deletes multiple files in the right pane of Windows
Explorer.
Could somebody please provide me with some guidance here? I would be
forever grateful. Thanks in advance.
Spike Pierson
GetFirstSelectedItemPosition
GetNextSelectedItem
GetNextItem
as LVM_GETNEXTITEM messages to the list control
and if you look up the documentation for either
GetNextItem or LVM_GETNEXTITEM you will see that
GetNextItem is general enough that you can use it to
search backwards through the selections.
CListCtrl m_wndList;
...
...
POSITION posItem;
while (posItem = m_wndList.GetFirstSelectedItemPosition())
{
int nIndex = m_wndList.GetNextSelectedItem(posItem);
m_wndList.DeleteItem(nIndex);
}
// End code snippet
Jay Nabonne
RightAgain, Inc.
"Spike Pierson" <SPie...@xostech.com> wrote in message
news:8uCH6.3362$e9.9...@news1.fdn.com...
"Jay Nabonne" <j...@rightagain.com> wrote in message
news:OZAEOHM1AHA.1608@tkmsftngp03...