Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine if an item is selected in a listview box

Using VB.net 2010 i am trying to figure out if an item was selected or not. Reason being is that if the user clicks on an item and pushes a button then everything works just fine. However, if the user selects an item and then clicks on a blank spot on the bottom of the listview and then clicks the button then it crashes.

My code is this:

    If (lstMaster.SelectedItems(0).SubItems(1).Text) Is Nothing Then
        MsgBox("test")
    End If

Any help would be great! :o)

David

like image 827
StealthRT Avatar asked Mar 30 '11 20:03

StealthRT


People also ask

How to check ListBox is selected or not?

To determine the items that are selected, you can use the Selected property of the list box. The Selected property of a list box is an array of values where each value is either True (if the item is selected) or False (if the item is not selected).

Which method is used to obtain the selected option from a ListView?

To get which item was selected, there is a method of the ListView called getItemAtPosition.


1 Answers

Ensure that something is selected first by checking that SelectedItems is not empty.

lstMaster.SelectedItems.Count > 0
like image 196
Grammarian Avatar answered Sep 21 '22 16:09

Grammarian