Regarding Visual C# MenuItem: Where does the NullReference come from?
- by Thomas
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?