Getting the listBox item at a given index location

Posted on 2004-11-21
Medium Priority
Last Modified: 2010-04-15
I have trouble getting the object associated with the given index of a listBox, unles I explicitly set the index ahead of time.

For example, I need to ...

listBox.SeletedIndex = 1;
Object object = listBox.SelectedItem

The problem with this is that you can see the listBox scroll through the choices, and it looks dumb.  

How do I simply get the item at a known index location.

Question by:ba272
1 Comment

Accepted Solution

aacool earned 2000 total points
ID: 12640928

ListBox.Items[k], where k is the known index location.

For example,

                  int pos = listBox1.Items.Count-2;
                  string selItem = listBox1.Items[pos].ToString();

you will not see any flicker or scrolling - I tested with at 25553-item list box

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

862 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