473,473 Members | 2,131 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Iterate thru menuitems of a contextmenu

Hello
I am trying to browse thru all menuitens of contextmenus.
The form has 3 contextmenus.

mi and mi2 as menuitems, f is a form

For Each mi In f.ContextMenu.MenuItems
For Each mi2 In mi.MenuItems

Next
Next

I get an Object reference not set to an instance of an
object. The ContextMenu = nothing...
What am i doing wrong? It works fine with MainMenus.

Thanks!

Kind Regards
Jorge Cavalheiro

Nov 20 '05 #1
5 1743
Hi there,

first, you don't say when this occure. Straight away or in the end or....

secondly try to put a try...catch around (or is it "on error <do this>") to
catch the error that is thrown and fetch the error message. it might give
you a clue

just a first hunch is that you run out of the limits somewhere, in the
beginning or at the end of the array.
/anders

"Jorge Cavalheiro" <jm**@NOSPAMdinefer.pt> wrote in message
news:d4****************************@phx.gbl...
Hello
I am trying to browse thru all menuitens of contextmenus.
The form has 3 contextmenus.

mi and mi2 as menuitems, f is a form

For Each mi In f.ContextMenu.MenuItems
For Each mi2 In mi.MenuItems

Next
Next

I get an Object reference not set to an instance of an
object. The ContextMenu = nothing...
What am i doing wrong? It works fine with MainMenus.

Thanks!

Kind Regards
Jorge Cavalheiro

Nov 20 '05 #2
Hello
This a procedure inside a class and called from the form
load event and its purpose is enable/disable certain menu
item based on user priviledges. My class has 4 methods
BrowsweMenus(form), BrowseButtons(form), ActivateMenus
(form) and ActivateButtons(form). All work just fine
except ContextMenus. Only one of them is associated to
the form.

Kind Regards
Jorge
-----Original Message-----
Hi there,

first, you don't say when this occure. Straight away or in the end or....
secondly try to put a try...catch around (or is it "on error <do this>") tocatch the error that is thrown and fetch the error message. it might giveyou a clue

just a first hunch is that you run out of the limits somewhere, in thebeginning or at the end of the array.
/anders

"Jorge Cavalheiro" <jm**@NOSPAMdinefer.pt> wrote in messagenews:d4****************************@phx.gbl...
Hello
I am trying to browse thru all menuitens of contextmenus. The form has 3 contextmenus.

mi and mi2 as menuitems, f is a form

For Each mi In f.ContextMenu.MenuItems
For Each mi2 In mi.MenuItems

Next
Next

I get an Object reference not set to an instance of an
object. The ContextMenu = nothing...
What am i doing wrong? It works fine with MainMenus.

Thanks!

Kind Regards
Jorge Cavalheiro

.

Nov 20 '05 #3
Hi Jorge,

I've tried to create a snippet to give me the error you describe. Not that
I'm a good programmer but I think you have missed to set an actrive
contextmenu, You said there where 2 of them right. I suppose that the app
don't know where to begin since there is multiple choise.

continnue to code a bit to see if I can find a solution

/anders

"Jorge Cavalheiro" <jm**@NOSPAMdinefer.pt> wrote in message
news:d1****************************@phx.gbl...
Hello
This a procedure inside a class and called from the form
load event and its purpose is enable/disable certain menu
item based on user priviledges. My class has 4 methods
BrowsweMenus(form), BrowseButtons(form), ActivateMenus
(form) and ActivateButtons(form). All work just fine
except ContextMenus. Only one of them is associated to
the form.

Kind Regards
Jorge
-----Original Message-----
Hi there,

first, you don't say when this occure. Straight away or

in the end or....

secondly try to put a try...catch around (or is it "on

error <do this>") to
catch the error that is thrown and fetch the error

message. it might give
you a clue

just a first hunch is that you run out of the limits

somewhere, in the
beginning or at the end of the array.
/anders

"Jorge Cavalheiro" <jm**@NOSPAMdinefer.pt> wrote in

message
news:d4****************************@phx.gbl...
Hello
I am trying to browse thru all menuitens of contextmenus. The form has 3 contextmenus.

mi and mi2 as menuitems, f is a form

For Each mi In f.ContextMenu.MenuItems
For Each mi2 In mi.MenuItems

Next
Next

I get an Object reference not set to an instance of an
object. The ContextMenu = nothing...
What am i doing wrong? It works fine with MainMenus.

Thanks!

Kind Regards
Jorge Cavalheiro

.

Nov 20 '05 #4
The outer loop (mi) is checking each menu item in the context menu.
If that item (mi) is not a sub-menu, then there will be a Nothing
reference for mi2., as mi has no menu items.

main menus are differnet in that you are iterating (mi) over each of
the menu "headers", and each one will typically have menu items in it.
But on a context menu, unless you're using sub-menus, none of the
mi's will have menu items.

Hope that helps,

Kevin

"Jorge Cavalheiro" <jm**@NOSPAMdinefer.pt> wrote in message news:<d4****************************@phx.gbl>...
Hello
I am trying to browse thru all menuitens of contextmenus.
The form has 3 contextmenus.

mi and mi2 as menuitems, f is a form

For Each mi In f.ContextMenu.MenuItems
For Each mi2 In mi.MenuItems

Next
Next

I get an Object reference not set to an instance of an
object. The ContextMenu = nothing...
What am i doing wrong? It works fine with MainMenus.

Thanks!

Kind Regards
Jorge Cavalheiro

Nov 20 '05 #5

Hi agin Jorge,

found this on MSDN,
http://msdn.microsoft.com/library/de...classtopic.asp
see the examplecode

Tested and it worked fine for me to create menuitems, both invisable and
disabled menitems,in a switched code snippet where iSecurityCode was
switched.

/anders

"Anders Sundberg" <an**********@hotmail.com> wrote in message
news:O1*************@TK2MSFTNGP12.phx.gbl...
Hi Jorge,

I've tried to create a snippet to give me the error you describe. Not that
I'm a good programmer but I think you have missed to set an actrive
contextmenu, You said there where 2 of them right. I suppose that the app
don't know where to begin since there is multiple choise.

continnue to code a bit to see if I can find a solution

/anders

"Jorge Cavalheiro" <jm**@NOSPAMdinefer.pt> wrote in message
news:d1****************************@phx.gbl...
Hello
This a procedure inside a class and called from the form
load event and its purpose is enable/disable certain menu
item based on user priviledges. My class has 4 methods
BrowsweMenus(form), BrowseButtons(form), ActivateMenus
(form) and ActivateButtons(form). All work just fine
except ContextMenus. Only one of them is associated to
the form.

Kind Regards
Jorge
-----Original Message-----
Hi there,

first, you don't say when this occure. Straight away or

in the end or....

secondly try to put a try...catch around (or is it "on

error <do this>") to
catch the error that is thrown and fetch the error

message. it might give
you a clue

just a first hunch is that you run out of the limits

somewhere, in the
beginning or at the end of the array.
/anders

"Jorge Cavalheiro" <jm**@NOSPAMdinefer.pt> wrote in

message
news:d4****************************@phx.gbl...
> Hello
> I am trying to browse thru all menuitens of

contextmenus.
> The form has 3 contextmenus.
>
> mi and mi2 as menuitems, f is a form
>
> For Each mi In f.ContextMenu.MenuItems
> For Each mi2 In mi.MenuItems
>
> Next
> Next
>
> I get an Object reference not set to an instance of an
> object. The ContextMenu = nothing...
> What am i doing wrong? It works fine with MainMenus.
>
> Thanks!
>
> Kind Regards
> Jorge Cavalheiro
>
.


Nov 20 '05 #6

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

Similar topics

0
by: Deutsche Dogge | last post by:
Hi. I'M having a weird problem with addign menuitems to a menu dynamically on the popup event of the menuitem containing the container of the menuitems i wanna add (tools -> external -> {list of...
2
by: Simon | last post by:
I've got a webform and many controls on it. I would like to iterate thru the control collection to get all the textboxes control to let me change the text property. Here is my code...for unknown...
0
by: Kreisquadratur | last post by:
Below is s snippet of my code, which should add menuitems as a submenu of an item in a contextmenu. But only the first time the contextmenu opens the entrys are set correctly. I just don't know why...
0
by: Brian | last post by:
Create a simple MDI form and a child form, and try the following simple code to add a new menu item on the Edit menu popup: private void editMenu_Popup(object sender, System.EventArgs e) {...
1
by: MrNobody | last post by:
For the the sake of keeping my code simple, I wanted a ContextMenu and a MainMenu to share some MenuItems, but it turns out when I Add() one MenuItem to the other it 'steals' that MenuItem so it...
5
by: Davie | last post by:
I'm developing an application on the smartphone. To reduce the size of the application i'm using panels where appropriate instead of forms. As a result of the design, I need to have different...
7
by: Dan Sikorsky | last post by:
How do you iterate thru a dataset to change money fields to a different value? Here's what I have. My dataset is filled directly from a stored procedure. ' Create Instance of Connection and...
0
by: Fred | last post by:
When I right click on a TextBox there is a default menu that pops up with the normal edit type (Undo, Cut, Copy, etc) items. If I set the ContextMenu property of the TextBox to a ContextMenu then...
1
by: Dean Slindee | last post by:
I have a toolStripDropDownButton with child toolStripDropDownMenuItems. I would like to iterate thru the toolStripDropDownMenuItems and look at the menuitems and discard the separators. Problem...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.