why isnt this code working

  • Thread starter Thread starter Abubakar
  • Start date Start date
A

Abubakar

HI all,
working in the vs.net 2k5 beta 2, I write the following code which gives me
an exception:
ContextMenu textboxmenu = textBox2.ContextMenu;
MenuItem menuitem = new MenuItem("hello");

textboxmenu.MenuItems.Add(0,menuitem);

its gives me an exception: "Object reference not set to an instance of an
object.". I understand this msg but its not so, cuz the variable "menuitem"
is properly intantiated and pointing to an object.

Regards,

Abubakar.
 
Hi,

Unless you have explicity set the ContextMenu property of the textBox2
object, this property is null, in which case you will get the exception
you are getting. Even though the standard windows Edit control has a context
menu it is not the represented in the .NET TextBox class by the ContextMenu
property.

Hope this helps
 
"Abubakar" <[email protected]> ha scritto nel messaggio

ContextMenu textboxmenu = textBox2.ContextMenu;
MenuItem menuitem = new MenuItem("hello");

textboxmenu.MenuItems.Add(0,menuitem);

its gives me an exception: "Object reference not set to an instance of an
object.". I understand this msg but its not so, cuz the variable "menuitem"
is properly intantiated and pointing to an object.

And the textboxmenu? ;)

Use the debug to understand the debug messages :)
 

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

Back
Top