How to find the selected entry

I have a List Ctrl in report mode. I want to find out the index of the selected entry. How?
rupak_khuranaAsked:
Who is Participating?
 
captainkirkConnect With a Mentor Commented:
try this:


POSITION pos = m_ListCtrl.GetFirstSelectedItemPosition();
int nItem = m_ListCtrl.GetNextSelectedItem(pos);
0
 
ZoppoCommented:
Hi rupak_khurana,

Generally you get list control's selected entries with i.e.:

// assuming m_List is your list control object
....
int nItem;
for ( POSITION pos = m_List.GetFirstSelectedItemPosition(); pos != NULL; )
{
 nItem = m_List.GetNextSelectedItem(pos);
 // do something with the item at index nItem
}
....

if you're sure there's only one selected item you can do
....
int nItem;
POSITION pos = m_List.GetFirstSelectedItemPosition();
if ( pos == NULL )
{
 // no item selected
 return;
}
nItem = m_List.GetNextSelectedItem(pos);
// do something with the item at index nItem
....

hope that helps,

ZOPPO
0
 
ZoppoCommented:
Hmmm, too late           :(

but you should check the return value from GetFirstSelectedItem() ...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.