PC Review


Reply
Thread Tools Rate Thread

convertion error

 
 
juli jul
Guest
Posts: n/a
 
      11th Jan 2005


Hello I am getting this error:
error CS0029: Cannot implicitly convert type 'System.EventHandler' to
'Janus.Windows.GridEX.ColumnActionEventHandler

Here are the declarations I made(all of them written in proper classes
and functions):

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




public event ChangedEventHandler Changed;


protected virtual void OnChanged(EventArgs e)

{

if (Changed != null)

Changed(this, e);

}

OnChanged(EventArgs.Empty);

class EventListener

{


public EventListener(Janus.Windows.GridEX.GridEX grid,Reader re)

{

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



}

private void GridexChanged(object sender, EventArgs e)

{



MessageBox.Show(this.re2.EL.Get_Val(gridex.Row).Stuck_Info.ToString());


}

}

Why do I get this error?
The weired thing is that if I am doing this for SelectionChanged eveny -
it doesn't happen.Why?
Thanks!




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
 
Benoit Vreuninckx
Guest
Posts: n/a
 
      11th Jan 2005
juli jul wrote:
>
> Hello I am getting this error:
> error CS0029: Cannot implicitly convert type 'System.EventHandler' to
> 'Janus.Windows.GridEX.ColumnActionEventHandler
>
> Here are the declarations I made(all of them written in proper classes
> and functions):
>
> public delegate void ChangedEventHandler(object sender, EventArgs e);
>
>
>
>
> public event ChangedEventHandler Changed;
>
>
> protected virtual void OnChanged(EventArgs e)
>
> {
>
> if (Changed != null)
>
> Changed(this, e);
>
> }
>
> OnChanged(EventArgs.Empty);
>
> class EventListener
>
> {
>
>
> public EventListener(Janus.Windows.GridEX.GridEX grid,Reader re)
>
> {
>
> this.gridex.CellEdited+=new EventHandler(GridexChanged);
>
>
>
> }
>
> private void GridexChanged(object sender, EventArgs e)
>
> {
>
>
>
> MessageBox.Show(this.re2.EL.Get_Val(gridex.Row).Stuck_Info.ToString());
>
>
> }
>
> }
>
> Why do I get this error?
> The weired thing is that if I am doing this for SelectionChanged eveny -
> it doesn't happen.Why?
> Thanks!
>
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!


Hi,

the CellEdited event must be of type ColumnActionEventHandler. You have
to create a delegate of that type, and assign it to the event.

-> this.gridex.CellEdited += new ColumnActionEventHandler(GridexChanged);

the method 'GridexChanged' must have the same signature (same
parameters) as in the declaration of the delegate ColumnActionEventHandler.

You don't get this problem with the SelectionChanged event as it
probably is declared as System.EventHandler.

To conclude, events only accept delegates of the same type.

Cheers,
Benoit
 
Reply With Quote
 
juli jul
Guest
Posts: n/a
 
      12th Jan 2005

Hello,
Thank you but I still got problems.I tried to change the type of handler
but I think that I still have problems with the type of an event.
Here is the code:

public delegate void ChangedEventHandler(object sender,
ColumnClickEventArgs e);

public event ChangedEventHandler Changed;

protected virtual void OnChanged(ColumnClickEventArgs e)
{
if (Changed != null)
Changed(this, e);

}

class EventListener
{
private Janus.Windows.GridEX.GridEX gridex;
private Reader re2;
public EventListener(Janus.Windows.GridEX.GridEX grid,Reader re)
{
this.gridex=grid;
this.gridex.CellEdited+=new ColumnActionEventHandler(GridexChanged);
}

private void GridexChanged(object sender, ColumnClickEventArgs e)
{


MessageBox.Show(this.re2.EL.Get_Val(gridex.Row).Stuck_Info.ToString()
);


}
}


I also tried the ColumnClickEventHandler - but it also didn't help.
I am getting errors.
What am I doing wrong?
Thanks a lot!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Benoit Vreuninckx
Guest
Posts: n/a
 
      12th Jan 2005
juli jul wrote:
> Hello,
> Thank you but I still got problems.I tried to change the type of handler
> but I think that I still have problems with the type of an event.
> Here is the code:
>
> public delegate void ChangedEventHandler(object sender,
> ColumnClickEventArgs e);
>
> public event ChangedEventHandler Changed;
>
> protected virtual void OnChanged(ColumnClickEventArgs e)
> {
> if (Changed != null)
> Changed(this, e);
>
> }
>
> class EventListener
> {
> private Janus.Windows.GridEX.GridEX gridex;
> private Reader re2;
> public EventListener(Janus.Windows.GridEX.GridEX grid,Reader re)
> {
> this.gridex=grid;
> this.gridex.CellEdited+=new ColumnActionEventHandler(GridexChanged);
> }
>
> private void GridexChanged(object sender, ColumnClickEventArgs e)
> {
>
>
> MessageBox.Show(this.re2.EL.Get_Val(gridex.Row).Stuck_Info.ToString()
> );
>
>
> }
> }
>
>
> I also tried the ColumnClickEventHandler - but it also didn't help.
> I am getting errors.
> What am I doing wrong?
> Thanks a lot!
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!


Hi,

ColumnActionEventHandler is defined as follow (if it hasn't been changed
by now):

public delegate void ColumnActionEventHandler(object sender,
ColumnActionEventArgs e);

which means, every event handler method, GridexChanged in your case,
must have the exact same parameters (called signature), in order to hook
it up on the event. You are specifying an *object* and
*ColumnClickEventArgs* in your method. The compiler won't accept this,
for a simple reason: when the event is fired, all handlers are invoked
with arguments of type *sender* and *ColumnActionEventArgs*, but your
method doesn't accept arguments of this type, as it has the wrong signature.
So, the delegate you assign (+=) to the event, must be of the same type
as the event (ColumnActionEventHandler), and the signature of the method
you pass to the constructor of the delegate must match the signature of
the delegate (object, ColumnActionEventArgs, and returning void).

1.

this.gridex.CellEdited += new ColumnActionEventHandler(GridexChanged);
(this one is correct)

2.

private void GridexChanged(object sender, ColumnActionEventArgs e)
{
MessageBox.Show(this.re2.EL.Get_Val(gridex.Row).Stuck_Info.ToString()
}

Cheers,
Benoit
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
field type convertion error Dan Microsoft C# .NET 7 20th Apr 2009 12:34 AM
type of data convertion error thread Microsoft Access 1 13th Apr 2007 02:42 PM
How do I populate a DataGridView with arrays containing strings? (I get convertion error C2664) Fleemox Microsoft Dot NET Framework Forms 2 18th Feb 2007 09:15 PM
convertion error juli Microsoft C# .NET 0 11th Jan 2005 02:29 PM
datetime convertion error juli Microsoft C# .NET 4 3rd Jan 2005 02:19 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:49 AM.