Solved

list box index

Posted on 2001-06-14
6
166 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET how to use the Vertical ScrollBar 5 90
Process filename extension 3 172
sameEnds challenge 3 135
sumNumber challenge 16 111
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

896 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

13 Experts available now in Live!

Get 1:1 Help Now