How to load a listbox with nothing selected

How can I load a listbox and not have the first line highlighted/selected.  Thanks
running32Asked:
Who is Participating?
 
PagodNaUtakConnect With a Mentor Commented:
After loading the items in the listbox execute this line of code:
listbox1.selectedindex = -1

Open in new window

0
 
rawinnlnx9Commented:
Change the focus of the form to a different control. So set it to

button.Focus();

Open in new window


I believe the listbox won't show selection if it is not selected. You can even set focus to the form or page.
0
 
running32Author Commented:
No that doesn't seem to work
0
 
Shahan AyyubSenior Software Engineer - iOSCommented:
Another alternative can be:

Control SelectionMode property of ListBox.

Private Sub Form2_Load(sender As Object, e As EventArgs)
	listBox1.SelectionMode = SelectionMode.None
End Sub

Private Sub listBox1_MouseClick(sender As Object, e As MouseEventArgs)
	listBox1.SelectionMode = SelectionMode.One
End Sub

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.