Solved

Detect if the user has selected an item

Posted on 2004-09-30
2
246 Views
Last Modified: 2010-04-15
Hi team, I am looking for a solution that will detect if the user has <u>not</u> choosen an item from a list box. The code below is what I have come up with and does not seem to provide me with the answer I am looking for.

public void GetSelections(ListBox _LBox) //Comments are same as above
            {
                  StringBuilder sb1 = new StringBuilder("");
                  StringBuilder sb2 = new StringBuilder("");
                  for(int i=0; i < _LBox.Items.Count; i++)
                  {
                        if(_LBox.Items[i].Selected)
                        {
                              sb1.Append(_LBox.Items[i].Text); //Return more than one Location, if selected
                              sb1.Append(","); //split muliple selections with ','.
                              sb2.Append(_LBox.Items[i].Value); //Return more than one Location id.
                              sb2.Append(","); //split multiple selections with ','.
                              if(_LBox.Items[i].Selected)
                              {
                                    _sbLocationIDs = null;
                                    _sbLocationsText = null;
                                    lblLocations.Text = "None Selected";
                              }
                              else
                              {
                                    _sbLocationIDs = sb2;
                                    _sbLocationsText = sb1;
                                    lblLocations.Text = "Selected Locations: " + sb1.ToString(); //Set the label equal to selections.
                              }
                        }
                        
                  }
Cheers

Wayne Atherton
0
Comment
Question by:watherton
2 Comments
 
LVL 5

Accepted Solution

by:
tomasX2 earned 50 total points
ID: 12189907
if( (_LBox.SelectedIndex == -1)
{
  // Then nothing is selected
}
0
 

Author Comment

by:watherton
ID: 12190932
Why do you always miss the simple ones?

Cheers tomasX2.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Suggested Solutions

Title # Comments Views Activity
PrintingFoundIt(Almost!(Damn!)) 1 30
Call Controller Action Method from ASPX 2 22
jquery + C#.net radiobuttonlist 3 30
Adding items to a C# list incrementally 5 30
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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

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