我想出了一个确实解决了我的问题的解决方案,但是我很好奇为什么我的初始方法失败了。我的情况如下所述:
我有一个引发事件的表格:
Public Class frmDgvLb
Public Delegate Sub ProfileChanged()
Public Event UpdateProfile As ProfileChanged
Private Sub lbDgvEdit_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles lbDgvEdit.SelectedIndexChanged
If UpdateHotlist(cmdStr) = True Then
If DgvName = "dgvHotlist" Then
Hotlist.LoadDGV()
ElseIf DgvName = "dgvJobProfile" Then
RaiseEvent UpdateProfile()
End If
Me.Close()
End If
End Sub
End Class
我有另一种定义和处理事件的形式:
Public Class frmGraph
Public Sub New()
InitializeComponent()
AddHandler frmDgvLb.UpdateProfile, AddressOf RefreshProfiles
End Sub
Public Sub RefreshProfiles()
GetProfiles(lbMach.SelectedItem, dtpJobDate.Value)
CreateGraph(dtpJobDate.Value, _machList)
zgc.Refresh()
End Sub
End Class
我的问题是 RaiseEvent UpdateProfile() 只会执行一次。列表框的所有后续索引更改都不会引发事件?当调试器单步执行时,当条件评估为真时,调试器将单步执行 RaiseEvent 行,然后单步执行关闭条件语句的行,并且 RefreshProfile Sub 永远不会执行。同样,列表框的索引第一次更改时,一切正常。为什么是这样?