【问题标题】:VB.Net SelectedChangeCommitted Throwing ErrorVB.Net SelectedChangeCommitted 抛出错误
【发布时间】:2013-10-23 15:06:44
【问题描述】:

我真的很生气。我不明白为什么这个事件总是抛出一个空白错误。下面是我的代码。

Private Sub cboSections_SelectedChangeCommitted(sender As System.Object, e As System.EventArgs) Handles cboSections.SelectionChangeCommitted
    On Error GoTo EH

    If TypeOf sender Is Windows.Forms.ComboBox Then
        'some boolean that checks if we are skipping this event, thus it does if so
        If mbSkipEvent Then Exit Sub

        'checks if index that was changed to is > 0 then it toggles the bottom command buttons
        If cboSections.SelectedIndex > 0 Then
            ToggleCmdButtons(True)
        Else
            ToggleCmdButtons(False)
        End If

        'sets the string msPurpose
        msPurpose = "Show Section"
        Debug.Print("Im here")
    End If
EH:
    Debug.Print("Error Description: " & Err.Description)
End Sub

在我的输出中,我得到“错误描述:”。就是这样。如果有人有任何解决方案或指出正确的方向,那就太好了。

【问题讨论】:

  • 错误转到?请救救我。
  • 我猜这是不好的做法......

标签: vb.net


【解决方案1】:

让我们尝试一些真正的错误处理,看看是否有更好的结果。在此过程中,我们可以稍微简化一下代码:

Private Sub cboSections_SelectedChangeCommitted(sender As System.Object, e As System.EventArgs) Handles cboSections.SelectionChangeCommitted
    Dim comboBox = TryCast(sender, ComboBox)
    If comboBox Is Nothing OrElse mbSkipEvent Then Exit Sub
    Try
       'checks if index that was changed to is > 0 then it toggles the bottom command buttons
       ToggleCmdButtons(cboSections.SelectedIndex > 0)

       'sets the string msPurpose
        msPurpose = "Show Section"
        Debug.Print("Im here")
    Catch Ex As Exception
        Debug.Print("Error Description: " & Ex.Message)
    End Try
End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-28
    • 2021-06-25
    相关资源
    最近更新 更多