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
Was it helpful?

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top