Link to home
Start Free TrialLog in
Avatar of rupak_khurana
rupak_khurana

asked on

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?
ASKER CERTIFIED SOLUTION
Avatar of captainkirk
captainkirk

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Zoppo
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
Hmmm, too late           :(

but you should check the return value from GetFirstSelectedItem() ...