I'm trying to pass an event handler to one of my method. This might look stupid but I can't seem to find a way to do it.
I have the red few questions here around on SO but I still don't get over it.
I have the following method signature
public void SyncWithInfo(Action<object, EventArgs> cellValueChanged,
int indexValeurFr, int indexValeurEn, int indexUnite)
And where I'm trying to call it using this piece of code
private void myMethod()
{
dgvform.SyncWithInfo(dgvform_CellValueChanged, valeur.Index,
valeurEN.Index, unite.Index);
}
private void dgvform_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
//stuff
}
I have the following error :
cannot convert from 'method group' to
'System.Action<object, System.EventArgs>'
From what I have red somewhere here on SO refering a method directly by its name without any parameter is considered a 'method group' since there could be X overload of that method.
So here is my question : How can I pass my event handler as an argument for my method?
I think that the SyncWithInfo signature has to use the explict type for EventArg. so that the method signature would look like:
public void SyncWithInfo(Action<object, DataGridViewCellEventArgs> cellValueChanged,
int indexValeurFr, int indexValeurEn, int indexUnite)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With