convertion error

J

juli jul

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!
 
B

Benoit Vreuninckx

juli said:
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!

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
 
J

juli jul

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!
 
B

Benoit Vreuninckx

juli said:
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!

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top