We help IT Professionals succeed at work.

How to find the selected entry

rupak_khurana
on
272 Views
Last Modified: 2013-11-20
I have a List Ctrl in report mode. I want to find out the index of the selected entry. How?
Comment
Watch Question

This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT

Commented:
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
CERTIFIED EXPERT

Commented:
Hmmm, too late           :(

but you should check the return value from GetFirstSelectedItem() ...
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.