Solved

Getting an un-selected item from a listbox

Posted on 2004-09-11
3
186 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
3 Comments
 
LVL 19

Accepted Solution

by:
drichards earned 500 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:Desp
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

705 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

11 Experts available now in Live!

Get 1:1 Help Now