Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

list box index

Posted on 2001-06-14
6
Medium Priority
?
186 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 400 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:Meir Rivkin
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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:Meir Rivkin
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

972 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