Solved

list box index

Posted on 2001-06-14
6
159 Views
Last Modified: 2013-11-20
How do I get the index of the item that is selected in the list box?
0
Comment
Question by:mejaz01
  • 3
  • 2
6 Comments
 
LVL 2

Accepted Solution

by:
MadYugoslav earned 100 total points
ID: 6190867
If there is just one selected item:
   with GetCurSel() You get the index of selected item in listbox.
If there are more selected items:
   with GetSelCount() You get the number of selected items and with GetSelItems() You get array with index of selected items.
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 6191038
here is an example:
     int cnt = m_srcList.GetSelCount();
     int *rgIndex = new int(cnt);
     m_srcList.GetSelItems(cnt, rgIndex);    

     
     CString str;

CStringArray strArry;
     for(int i=0; i<cnt; i++){
          m_srcList.GetText(rgIndex[i], str);
               strArry.Add(str);
     }

now strArray contain the selected items and rgIndex contain array of the indexes of the selected items

good luck
0
 
LVL 2

Expert Comment

by:MadYugoslav
ID: 6191061
To sedqwick !
That solution will not work if in listbox is not allowed multiselect.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 2

Expert Comment

by:MadYugoslav
ID: 6191082
To mejaz01 !
In my comment words if there is just one selected item or more than one item means that your list box alow to select just one or more items (mean what style is checked: multiselect or single select).
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 6191209
sorry MadYugoslav, i was typing while your comment was posted.

0
 

Author Comment

by:mejaz01
ID: 6191397
I have a listbox that selects single item.  It was a nice solution
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now