error :Cannot implicitly convert type

  • Thread starter Thread starter juli
  • Start date Start date
J

juli

I declared:
public delegate void PaintEventHandler(object objSender,PaintEventArgs
pea);
and
this.Paint+=new PaintEventHandler(MyPaintHandler);
and the:
static void MyPaintHandler(object objSender,PaintEventArgs pea)
{
}


I got this error:

Cannot implicitly convert type 'deleg.Form1.PaintEventHandler' to
'System.Windows.Forms.PaintEventHandler'
 
reason is this --

this.Paint is actually a event which is declared as following

public event System.Windows.Forms.PaintEventandler Paint

....and NOT...

public event deleg.Form1.PaintEventHandler Paint

so, if you try to give your own override to it it will give error
 
small typo, please read ------

public event System.Windows.Forms.PaintEventHandler Paint
-------------------------------------------------^
 
Thanks for the reply but I keep having the same error in this case also:

class EventListener
{
private Janus.Windows.GridEX.GridEX gridex;
public EventListener(Janus.Windows.GridEX.GridEX grid)
{
this.gridex=grid;
this.gridex.SelectionChanged+=new ChangedEventHandler(GridexChanged);
}

private void GridexChanged(object sender, EventArgs e)
{
Console.WriteLine("This is called when the event fires.");
}
}


-------------------------------------------------------
in other class:
EventListener listener = new EventListener(this.gridex_exc);

and the delegate:
public delegate void ChangedEventHandler(object sender, EventArgs e);

Why I keep having this error? Thanks!

error:
error CS0029: Cannot implicitly convert type
'WindowsApplication2.ChangedEventHandler' to 'System.EventHandler'
 
juli said:
Thanks for the reply but I keep having the same error in this case also:

class EventListener
{
private Janus.Windows.GridEX.GridEX gridex;
public EventListener(Janus.Windows.GridEX.GridEX grid)
{
this.gridex=grid;
this.gridex.SelectionChanged+=new ChangedEventHandler(GridexChanged);
}

private void GridexChanged(object sender, EventArgs e)
{
Console.WriteLine("This is called when the event fires.");
}
}


-------------------------------------------------------
in other class:
EventListener listener = new EventListener(this.gridex_exc);

and the delegate:
public delegate void ChangedEventHandler(object sender, EventArgs e);

Why I keep having this error? Thanks!

error:
error CS0029: Cannot implicitly convert type
'WindowsApplication2.ChangedEventHandler' to 'System.EventHandler'

How is the Janus.Windows.GridEX.GridEX.SelectionChanged event declared.
I suspect it is declared as:

public event EventHandler SelectionChanged;

This is ok, as your ChangedEventHandler delegate has exactly the same
signature as the System.EventHandler delegate. It really doesn't bring
anything new to the table.

Either change the SelectionChanged to use your ChangedEventHandler
delegate, or change your event subscription code to:

this.gridex.SelectionChanged+=new EventHandler(GridexChanged);

/Joakim
 
If you find these kind of problems, the best is to use object browser as it
gives you the idea of how things are and can be used.

Thanks,
Ashish Das
 
Back
Top