Reputation: 19
I'm facing a problem to call the event [dgv_clients_UserDeletingRow]
using a [ContextMenuStrip]
.
It's giving me that error:
Unable to cast object of type 'System.EventArgs' to type 'System.Windows.Forms.DataGridViewRowCanelEventArgs'
And here is my code :
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
Thank your all
Upvotes: 0
Views: 630
Reputation: 26
The Problem is your deleteLine
method.
You are calling it with two different types. In the Sub dgv_clients_UserDeletingRow
you pass e as DataGridViewRowCancelEventArg
s and in the Sub DeleteToolStripMenuItem_Click
you pass e as EventArgs
. If you haven't overloaded your deleteLine
method for these two types, the compiler will try to auto-parse the wrong type and it fails.
Upvotes: 1