Listbox check if an item is selected
Iv been trying to figure this out for hours ok so basically i need a to check if there is an item selected in listbox1
Heres the code in trying to make work
Code:
If ListBox1.SelectedItem = True Then
ListBox2.Items.RemoveAt(ListBox1.SelectedIndex)
ListBox3.Items.RemoveAt(ListBox1.SelectedIndex)
ListBox4.Items.RemoveAt(ListBox1.SelectedIndex)
ListBox5.Items.RemoveAt(ListBox1.SelectedIndex)
ListBox6.Items.RemoveAt(ListBox1.SelectedIndex)
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
ElseIf MsgBox("Please select a username") Then
End If
Re: Listbox check if an item is selected
Just use the selected index property:
vb Code:
If Me.ListBox1.SelectedIndex >= 0 then
'something is selected
Else
'Nothing is
End If
Justin
Re: Listbox check if an item is selected
You just need to check whether the selected index is not -1. So...
vb Code:
If Not myListbox.SelectedIndex = -1 Then
'Do something
End If
Re: Listbox check if an item is selected
Justin your always to fast for me :(
Re: Listbox check if an item is selected
Lol, yeah I hate it when that happens... But regardless, we both provided a suitable solution : ).
Justin
Re: Listbox check if an item is selected
on heels of that... there's a reason that this doesn't work:
If ListBox1.SelectedItem = True Then
SelectedItem returns a ListViewItem ... not a boolean...
If ListBox1.SelectedItem IsNot Nothing Then
...
-tg