我使用[dgv_clients_UserDeletingRow]
调用事件[ContextMenuStrip]
时遇到问题。
它给了我这个错误:
Unable to cast object of type 'System.EventArgs' to type 'System.Windows.Forms.DataGridViewRowCanelEventArgs'
这是我的代码:
Private Sub dgv_clients_UserDeletingRow(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewRowCancelEventArgs) Handles dgv_clients.UserDeletingRow
deleteLine(e)
End Sub
Private Sub toolStripItem1_Click(ByVal sender As Object, ByVal args As EventArgs) Handles toolStripItem1.Click
If mouseLocation.RowIndex > 0 Then
dgv_clients.Rows(mouseLocation.RowIndex).Selected = True
dgv_clients.Rows(mouseLocation.RowIndex).DefaultCellStyle.SelectionBackColor = Color.Gray
DeleteToolStripMenuItem_Click(sender, args)
End If
End Sub
Public Sub DeleteToolStripMenuItem_Click(ByVal Sender As Object, ByVal e As EventArgs)
Call deleteLine(e)
End Sub
谢谢大家
答案 0 :(得分:1)
问题是您的deleteLine
方法。
您使用两种不同的类型调用它。在Sub dgv_clients_UserDeletingRow
传递e as DataGridViewRowCancelEventArg
和Sub DeleteToolStripMenuItem_Click
传递e as EventArgs
。如果你没有为这两种类型重载deleteLine
方法,编译器将尝试自动解析错误的类型并且失败。