Question

I want to disable few item in a contextmenu or menustrip when an item in listbox is selected, I manage to do it in a listview control but I can't convert it to listbox, there is no ListItem in listbox control, can i do it using this code, or perhaps an entirely different code, thanks for helping..

Private Sub cIconList_Opening(sender As System.Object, e As System.ComponentModel.CancelEventArgs) Handles cIconList.Opening
    Dim item As ListViewItem = Nothing
    If lvIcon.SelectedIndices.Count = 1 Then
        item = TryCast(lvIcon.SelectedItems(0), ListViewItem)
    End If
    mnuExtractIcon.Enabled = (item IsNot Nothing)
    mnuIconProperties.Enabled = (item IsNot Nothing)
End Sub
Était-ce utile?

La solution

If you are trying to disable another form object when any ListBox item is selected, just add this to the ListBox's SelectedIndexChanged event.

AnyFormObject.Enabled = (ListBoxObject.SelectedIndex = -1)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top