By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,933 Members | 1,563 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,933 IT Pros & Developers. It's quick & easy.

Iterate thru menuitems of a contextmenu

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

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 discussion thread is closed

Replies have been disabled for this discussion.