문제

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
도움이 되었습니까?

해결책

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)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top