Regarding Visual C# MenuItem: Where does the NullReference come from?

Posted by Thomas on Stack Overflow See other posts from Stack Overflow or by Thomas
Published on 2010-05-31T08:44:48Z Indexed on 2010/05/31 8:53 UTC
Read the original article Hit count: 265

Filed under:
|

Hi All.

I have a problem creating MenuItems for a TreeView dynamically: here is the (simplified)code i'm using.

public class CTM : TreeNode, IComparable, IComparable<CTM>
{
    public CTM(CTMProvider provider)
    {
        this.provider = provider;
        this.manager = provider.manager;
        this.IEEEAddress = provider.IEEEAddress;
        this.endpoint = provider.state._conn.RemoteEndPoint;
        this.Text = String.Format("CTM: {0} {0}", IEEEAddress, ((System.Net.IPEndPoint)endpoint).ToString());
        try {
            MenuItem meni = System.EventHandler(this.provider.Disconnect));
            this.ContextMenu.MenuItems.Add(meni);
        } catch {
            Trace.TraceError("Could not create menu item!");
        }
    }
}

This code always triggers the catch clause with a NullReferenceException. Any Ideas?

© Stack Overflow or respective owner

Related posts about c#

Related posts about winforms