By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,720 Members | 2,135 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,720 IT Pros & Developers. It's quick & easy.

How to select multiple items on a listbox?

P: 9
How to select multiple items on a listbox?
Jan 28 '16 #1
Share this Question
Share on Google+
1 Reply

P: 82
First you need to set the ListBox.SelectionMode property to ether MultiSimple or MultiExtended depending on how you want the selection process to work in the ListBox. Then you can select multiple items in the ListBox with the Mouse.

If you want to set the selected items in code, then you can do it by adding the Indexes of the items you want selected to the ListBox.SelectedIndices collection as shown in the example below.

Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  4.         ListBox1.SelectionMode = SelectionMode.MultiSimple
  5.     End Sub
  7.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  8.         ListBox1.SelectedIndices.Add(1)
  9.         ListBox1.SelectedIndices.Add(3)
  10.         ListBox1.SelectedIndices.Add(6)
  11.     End Sub
  12. End Class
You could also do it by adding the Items you want selected to the SelectedItems collection.
Jan 28 '16 #2

Post your reply

Sign in to post your reply or Sign up for a free account.