How to select all items in a listbox 
Author Message
 How to select all items in a listbox

I have been trying to select all items in a listbox.

Thanks in advance.

- Chad



Sun, 22 May 2005 02:59:02 GMT  
 How to select all items in a listbox
Hi Chad,

There is no direct way to select all items but you can use
ListBox.SetSelected(int, bool) to do multiple selection.
You can use ListBox.ClearSelected to clear all.

Hope this would help.

John
--
This posting is provided "AS IS" with no warranties, and confers no rights.

Quote:
> I have been trying to select all items in a listbox.

> Thanks in advance.

> - Chad



Sun, 22 May 2005 04:55:35 GMT  
 How to select all items in a listbox
This should work:
First change the SelectionMode property of the listbox to allow multiple
selection (from the property window or using teh following code)
Me.ListBox1.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended

Then use this:

Dim i As Integer
For i = 0 To Me.ListBox1.Items.Count - 1
     Me.ListBox1.SetSelected(i, True)
Next

Luca Dellamore
VB Team
--
This posting is provided "AS IS" with no warranties, and confers no rights.

Quote:
> I have been trying to select all items in a listbox.

> Thanks in advance.

> - Chad



Sun, 22 May 2005 05:20:10 GMT  
 How to select all items in a listbox
First make sure your ListBox is multi-selectable.  This is achieved by
setting the Property ListBox1.SelectionMode = ListSelectionMode.Multiple

Then use a for each loop

Dim li As ListItem
For Each li In ListBox1.Items
    li.Selected = True
Next

Ting
MS VB.NET Team
--
This posting is provided "AS IS" with no warranties, and confers no rights.

Quote:
> I have been trying to select all items in a listbox.

> Thanks in advance.

> - Chad



Sun, 22 May 2005 05:19:43 GMT  
 How to select all items in a listbox
You have to set listbox.SelectionMode to be multiselection first. Then call
listbox.SetSelected to select the item you want:

ListBox1.SelectionMode = SelectionMode.MultiSimple
ListBox1.SetSelected(0, True)
ListBox1.SetSelected(1, True)
ListBox1.SetSelected(2, True)
...

Yu-Fang
MS Visual Basic Development Team

--
This posting is provided "AS IS" with no warranties, and confers no rights.

___

Quote:
> I have been trying to select all items in a listbox.

> Thanks in advance.

> - Chad



Sun, 22 May 2005 05:22:34 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Can you select an item in a listbox thru VBA

2. How To: Select a item in a listbox by the itemdata

3. How To Select an item in a listbox

4. populating vb.net listbox from selected items of another listbox

5. How to select an Item in a Listbox control?

6. How to select an Item in a Listbox control?

7. Selecting Item In Listbox

8. Selecting All Items In a MultiSelect ListBox

9. Remove selected item from listbox

10. Programmatically selecting items on ListBox problem

11. Setting ListBox item to selected..

12. Controlling Selected Items in a MultiSimple ListBox

 

 
Powered by phpBB® Forum Software