-
Jul 2nd, 2010, 01:53 PM
#1
Thread Starter
Junior Member
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
-
Jul 2nd, 2010, 01:58 PM
#2
Frenzied Member
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
-
Jul 2nd, 2010, 02:02 PM
#3
Member
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
-
Jul 2nd, 2010, 02:02 PM
#4
Member
Re: Listbox check if an item is selected
Justin your always to fast for me
-
Jul 2nd, 2010, 02:12 PM
#5
Frenzied Member
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
-
Jul 2nd, 2010, 03:25 PM
#6
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
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
|
Click Here to Expand Forum to Full Width
|