-
How to clear selected items from a list box
Hi,
I have a problem clearing the selected items fom a list box (MultiExtended). I have tried with:
listboxName.SelectedItems.Clear()
but nothig happens. When I loop and use GetSelected(x) and then RemoveAt(x) if GetSelected(x) = True I can remove selected items but only one by one. Can anybody please explain why listboxName.SelectedItems.Clear() is not working and show me the best and easiest way to clear all items that are selected on a list box by one click on a button?
Thanking you in advance
Nesha
-
Mabe there is no better way.
There is two collection.
ObjectCollection
SelectedObjectCollection
istboxName.SelectedItems.Clear() just Removes all items from SelectedObjectCollection.
Removing itme from ObjectCollection must use ObjectCollection's methods.
-
Thanks for the reply. You maight be right. I solved the problem the other way, but it just don't make sence: what's the difference between listboxname.Items.Clear() and listboxname.SelectedItems.Clear()?
Regards
Nesha
-
Nesha,
SelectedItems.Clear results in no items being selected.
Items.Clear results in no items remaining in the listbox.
To actually remove the selected items from the listbox, you could do something like this:
For i As Integer = (ListBox1.SelectedItems.Count - 1) To 0 Step -1
ListBox1.Items.Remove(ListBox1.SelectedItems(i))
Next
Kerry Moorman
-
Thank you, this clears things. Also, this is much more elegant solution than mine.
Regards
Nesha
-
Kerry,
Ran across that code. Hope you don't mind if I use this for my high school assignment. Much appreciation.
Croomie
-
-
this is the code for clearing the list box just by clicking once:
ListBox1.items.clear
Similar Threads
-
Replies: 1
Last Post: 05-25-2001, 10:41 PM
-
By Ben in forum VB Classic
Replies: 2
Last Post: 02-21-2001, 02:13 PM
-
By Grego in forum VB Classic
Replies: 2
Last Post: 11-13-2000, 08:51 AM
-
Replies: 0
Last Post: 09-18-2000, 05:04 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks