Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to get selected item in ClistCtrl??

26 views
Skip to first unread message

lee...@vse.seisea.com.sg

unread,
Jun 2, 1999, 3:00:00 AM6/2/99
to
Hi all,
think my previous question was not too clear.

So how do you get the selected item or items in CListCtrl??? for one
selected item I used the mylist.GetSelectionMark....but I have not idea
how to get the index of all the selected items. Let's assume that user
can only items that are consective to each other. That is the user
cannot select item with index 0 and 3 at the same time.

Also, if I want to delete all the selected items after I got the index
of all the item in the list, how do I do that??

Thanks in Advance. Any help will be greatly apprecitated.

leesze..
********************************************************
*As Imagination Bodies Forth
*The Forms Of Things Unknown, The Poet's Pen
*Turns Them To Shapes, And Gives To Airy
Nothing
*A Local Habitation And A Name
*
********************************************************

Dennis Jump

unread,
Jun 23, 1999, 3:00:00 AM6/23/99
to
Here is some sample code that will detect which items are selected.

void CMyView::GetListItems()
{
int n = m_trip_list.GetItemCount();
int status = 0;
int data = 0;
for(int i=0;i< n;i++)
{
status = m_list.GetItemState(i,LVIS_SELECTED);
if ((status & LVIS_SELECTED) == 0) continue; // not selected
data = m_list.GetItemData(i);
}
}

Start at the end of the list if you want to delete them as you work your way
forward. DeleteItem() should do that just fine.

Dennis
soft...@iglobal.net

lee...@vse.seisea.com.sg wrote in message

Joel Schultz

unread,
Jun 23, 1999, 3:00:00 AM6/23/99
to
An easier way to do this is the following:

// Get index of item that is selected, starting search from beginning of
list
int nSelItemIndex = pListControl->GetNextItem(-1, LVNI_SELECTED);
while (nSelItemIndex != -1) // Was an item found?
{
// Do something with the index of the selected item

// The below might need bounds checking for nSelItemIndex + 1 being a
valid index...
nSelItemIndex = pListControl->GetNextItem(nSelItemIndex + 1,
LVNI_SELECTED);
}

Or try this (looks like the typical iterator MS uses in the doc/view
architecture):

POSITION pos = pListControl->GetFirstSelectedItemPosition();
while (pos) // Loop through all selected items
{
int nSelItemIndex = pListControl->GetNextSelectedItem(pos);
// Do something with the index of the selected item
}

Dennis Jump <soft...@iglobal.net> wrote in message
news:93015412...@news.remarQ.com...

0 new messages