Solved

Detect if the user has selected an item

Posted on 2004-09-30
2
258 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

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…
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!
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

710 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