Solved

list box index

Posted on 2001-06-14
6
172 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to monitor remote shell execution on linux 9 104
sameEnds challenge 3 180
NotAlone Challenge 20 84
JQuery serialize and unserialize 8 135
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

856 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