468,556 Members | 2,395 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,556 developers. It's quick & easy.

error :Cannot implicitly convert type

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'
Nov 16 '05 #1
6 14029
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
"juli" <ji****@gmail.com> wrote in message
news:1f**************************@posting.google.c om...
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'

Nov 16 '05 #2
small typo, please read ------

public event System.Windows.Forms.PaintEventHandler Paint
-------------------------------------------------^
"Ashish Das" <yh****@hotmail.com> wrote in message
news:OL**************@TK2MSFTNGP11.phx.gbl...
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
"juli" <ji****@gmail.com> wrote in message
news:1f**************************@posting.google.c om...
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'


Nov 16 '05 #3
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'
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #4
juli jul wrote:
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'
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


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
Nov 16 '05 #5

Thank you very much! It helped.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #6
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

"juli jul" <ju******@yahoo.com> wrote in message
news:es****************@TK2MSFTNGP15.phx.gbl...

Thank you very much! It helped.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by George Bell | last post: by
2 posts views Thread by Patrick Olurotimi Ige | last post: by
reply views Thread by erik.erikson | last post: by
reply views Thread by nithya176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.