Problem matching Delegate Signature

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am having a problem matching a delegate signature

I have a "Checked ListBox" and I am trying to assign a method to the event like this

this.ckLst.SelectedIndexChanged += new System.EventHandler(this.ckLst_SelectedIndexChanged)

What I want is this signature [NOTE, the default is [System.EventArgs]]

private void ckLst_SelectedIndexChanged(object sender, ItemCheckEventArgs e

if (e.NewValue == e.CurrValue

// then do somethin



Is this possible? I cannot tell from the documentation or the books that I have if this is even possible

I get this erro
C:\Tools\frmList.cs(72): Method 'EmpManager.frmTblList.ckLst_SelectedIndexChanged(object, System.Windows.Forms.ItemCheckEventArgs)' does not match delegate 'void System.EventHandler(object, System.EventArgs)
 
Hi,

IMHO this is not possible, the signature of delegate signature and the
signature of the delegate handler are required to be identical. But you may
use the derived event args by casting the EventArgs argument to
ItemCheckEventArgs type in the handler method as below:

private void ckLst_SelectedIndexChanged(object sender, EventArgs e)
{
ItemCheckEventArgs args = e as ItemCheckEventArgs;
if (e != null &&e.NewValue == e.CurrValue)
{
// then do something
}
}

does this way solve your problem?


Best regards,

Ying-Shen Yu [MSFT]
Microsoft community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
 
Back
Top