473,404 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

why isnt this code working

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.


Nov 17 '05 #1
3 1235
"Abubakar" <em**********@yahoo.com> ha scritto nel messaggio
news:ud**************@TK2MSFTNGP10.phx.gbl...

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 :)

--
..Net Reporting tool: http://www.neodatatype.net
Nov 17 '05 #2
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

--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor
"Abubakar" <em**********@yahoo.com> wrote in message
news:ud**************@TK2MSFTNGP10.phx.gbl...
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.

Nov 17 '05 #3
thanks to all :)

Ab.

"Zanna" <zn*******@virgilio.it> wrote in message
news:Hu*********************@news4.tin.it...
"Abubakar" <em**********@yahoo.com> ha scritto nel messaggio
news:ud**************@TK2MSFTNGP10.phx.gbl...

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 :)

--
.Net Reporting tool: http://www.neodatatype.net


Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jon via DotNetMonster.com | last post by:
<siteMapNode title="share price" description="Link to Netcall on the London Stock Exchange" url="http://www.yahoo.co.uk" role="" target="_blank" /> Hi all I'm trying to open the Yahoo web...
0
by: milkay | last post by:
<I have code that uses 2 images> the program creates a window and then when u press play, it removes all components in the container. then, i add a NewPanel object. i add mouse listeners and all...
7
by: robert.waters | last post by:
I have an Access database frontend linked via ODBC to a large (gigabytes) mysql database. I need to view a large amount of data in a a textbox (variable up to 300K), but I receive a 'there isnt...
4
by: Badboy112 | last post by:
Hi guys im not sure what i am doinf wrong but the if statement in the action performed is not working any ideas import java.io.*; import javax.swing.*; import java.awt.*; import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.