referencing Menu Items in code

F

Felicity

Hello,

I have a dilema relating to Menu Items. On a Main Form I
have a single Main Menu object that has many MenuItems
associated with it. In some cases extra menu items are
added and some removed if the Main Form is opened from a
particular area of the sytem. When this occurs the Index
property of the Menu Items changes. I also set the text
of the Menu Items depending on some custom settings chosen
by the user. This means that for some Menu Items, the
text can be anything.

My problem is that at some point during the load of the
form, I need to set some of the menu items as enabled or
disabled depending on the security settings of the user,
which are held in a table in my database. However, I
cannot reference the Menu Item in code as it does not
appear to have a "name" property and the only other two
properties that I could use, "index" and "text", are
continually changing. Does anyone know a way that I can
reference the Menu Items in code?

Please help me !!!

Thanks in advance,

Felicity
 
B

Bob Powell [MVP]

Keep a reference to your menu items in a HashTable along with some info
about the menu item such as a unique identifier or a command string. When
the parent menu popup comes along, get the references from the hashtable and
use them to decide whether the item should be enabled or whatever.

Ideally, you could create an extender-provider component to manage this.

--
Bob Powell [MVP]
C#, System.Drawing

The October edition of Well Formed is now available.
Find out how to use DirectX in a Windows Forms control
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com
 

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

Top