Solved

Detect if the user has selected an item

Posted on 2004-09-30
2
223 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
Comment Utility
if( (_LBox.SelectedIndex == -1)
{
  // Then nothing is selected
}
0
 

Author Comment

by:watherton
Comment Utility
Why do you always miss the simple ones?

Cheers tomasX2.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: Ivo
Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

728 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

9 Experts available now in Live!

Get 1:1 Help Now