The MouseClick
event of DataGridView
actually provides a MouseEventArgs
argument. You declared your datagridview1_MouseClick
method only with EventArgs
.
Change that to
protected void datagridview1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == ...
and it should work (in case you used CellMouseClick
instead of MouseClick
, use DataGridViewCellMouseEventArgs
instead of MouseEventArgs
).
As a side note: you don't get a compilation error when you add your "wrongly" declared handler like datagridview1.MouseClick += datagridview1_MouseClick
, because MouseEventArgs
is derived from EventArgs
, so the compiler has no problem with that assignment. The problem arises when you try to access the properties of a MouseEventArgs
instance via e
when e
is declared as EventArgs
, because EventArgs
doesn't know the properties of the MouseEventArgs
derivate.
P.S.: Please post your code as text to your next question. It's better for us to read or to re-use for reproducing the error than an image. In that image, I can't see if you used the MouseClick
or CellMouseClick
event