我正在尝试使用以无结尾的各种选项制作ListBox
。如果选择无,我想清除其他选项,只选择无。如果选择了其他内容,则会清除“无”,并且用户可以选择适用的条款。
清除无工作正常,但在选择“无”时尝试清除其余项目会给我带来问题。我不断收到以下错误:
Change()事件中的Listbox
会调用自身,这就是为什么我添加行以使其退出EventsEnabled = FALSE
。但是,它并不想更新和清除列表,并且根据我放置任何特定行的位置,它会在该行上引发错误。我玩过的最多的两个是将 None 设置为选中的行,以及重新启用事件的行;两个都给我一个错误,取决于我放置它们的顺序。
有什么建议吗?我在做一些我需要处理的奇怪的循环事吗?是否有更简单的方法来保持Change不会自己调用?
相关代码:
Private Sub Reprogramming_ListBox_Change()
' Using this to check for a None answer. If None is selected,
' it will clear out all other selections.
' Selecting another item will unselect None.
If Me.EnableEvents = False Then
Exit Sub
End If
none_Index = Reprogramming_ListBox.ListCount - 1
If None_Selected Then
' Check to see if the new entry is something other than None
' Unselect None and udpate None Flag
If Reprogramming_ListBox.ListIndex <> none_Index Then
None_Selected = False
Reprogramming_ListBox.Selected(none_Index) = False
End If
Else
' Check to see if new entry is None
If Reprogramming_ListBox.ListIndex = none_Index Then
' Copy-Paste this code, because I think
' that will solve my unintended recursion issue
Me.EnableEvents = False
Reprogramming_ListBox.MultiSelect = fmMultiSelectSingle
Reprogramming_ListBox.Value = ""
None_Selected = True
Me.EnableEvents = True
Reprogramming_ListBox.Selected(none_Index) = True
Reprogramming_ListBox.MultiSelect = fmMultiSelectMulti
' If it is None, clear out other entries
End If
End If
End Sub