Solved

Detect if the user has selected an item

Posted on 2004-09-30
2
265 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
[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
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

615 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