We help IT Professionals succeed at work.

Clear listbox selection

371 Views
Last Modified: 2013-11-07
I have a list box and when I populate it, the first choice is auto selected.  How can I populate the list box, but not have anything selected forcing the user to make the selection?
Comment
Watch Question

ListBox? in ASP.net?

Nothing gets selected by default.

But still u get some selected, u can use ListBox1.ClearSelection()

Author

Commented:
Im using visual basic, but when I populate the list box from an array, the first selection is highlighted.  I dont want this to happen because that causes another process to happen.
Dint this work?

ListBox1.ClearSelection()

Author

Commented:
Nope, that will clear the selection I am on, but then will default back to the first selection in the listbox.  I was hoping to not have anything selected until the user clicks on it.
can u post ur code and the aspx of the listbox
Anurag ThakurTechnical Manager

Commented:
use the selectedindex property of list box and set it to -1 to clear the selection even the default one too
http://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.selectedindex.aspx
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Commented:
oooppss.. haven't able to read what ragi0017 posted.

Well, ragi mentioned setting the SelectedIndex = -1  first.

Sorry bro...
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.