Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Getting an un-selected item from a listbox

Posted on 2004-09-11
3
Medium Priority
?
193 Views
Last Modified: 2010-04-15
Hi,

I have no problem getting a selected item from a listbox.  But I'd like to get an item (by item number) which is not selected.  For example, I'd like the item at position zero and each item thereafter.  But I'd like to do this without having to select each item before I can access the item.

I looked in the C# help but it's not obvious to me.  

Thanks for the help,
RA
0
Comment
Question by:ba272
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 19

Accepted Solution

by:
drichards earned 2000 total points
ID: 12035577
The Items collection gives you access to all the ListBox items.  It's available in both the Windows.Forms and the Web.UI... versions of ListBox.

So you'd do something like:

    listBox1.Items[n]

to access the item at index n (starting with 0).
0
 
LVL 23

Expert Comment

by:rama_krishna580
ID: 12036763
Hi,

Look at this example...
http://www.thecodeproject.com/cs/media/SystemPainter.asp

it may help you..
R.K
0
 
LVL 19

Expert Comment

by:Fahad Mukhtar
ID: 12037625
To get a single unselected item you can use the by-default 'Items' collection of listBox object:
listBox1.Items[n]

but you MUST be sure that Item at Items[n] is NOT SELECTED because it may be possible that the Items[n] is selected as the Items Collection contains all the items (Selected +  Unselected)

The following Code will make an arraylist of All UN SELECTED items in a listbox:

ArrayList UnSelectedItems = new ArrayList();

for (int i  =0 ; i < listBox1.Items .Count ; i++)
    if (!listBox1.SelectedItems.Contains(listBox1.Items[i]))
           UnSelectedItems.Add(listBox1.Items[i]);

Later you can print the values to see that all the printed values are NOT SELECTED

for (int i  =0 ;j<UnSelectedItems.Count ;j++)
     Console.WriteLine(UnSelectedItems[j].ToString());


hth,
Fahad Mukhtar
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

604 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