youssef1700
youssef1700

Reputation: 109

which event should my listview handle to do an action when any item is selected in VB.net

i need help to desactivate a button when there are any item select in my listview. here is my code :

Private Sub ListView_ItemSelectionChanged(____) Handles ListView.ItemSelectionChanged
    If ListView.SelectedItems.Count > 0 Then
        btnDelete.Enabled = False
    End If
End Sub

i need to know which event shoul my procedure handle to make my program work correctly.

Upvotes: 1

Views: 84

Answers (1)

jmcilhinney
jmcilhinney

Reputation: 54487

Surely you want Enabled to be True when items are selected, not False. The other problem I see with your code is that it's not disabling the Button again if no item is selected. Do this instead:

btnDelete.Enabled = (ListView.SelectedItems.Count > 0)

I'd also try a descriptive name for your ListView.

Upvotes: 1

Related Questions