473,834 Members | 2,063 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to find a MenuItem's name, or, there's no more Tag property

I have an application where I need to set certain menu items invisible based on a
user privilege.

We did a sinmlar thing in VB6 and used the menu item's tag property to assign an
identifier to each menu entry, then used that identifier as an index into a
collection populated at user login in order to determine the item's visibility.

Now, for some reason there's no tag property for .NET MenuItems, so I'm looking for
some way to accomplish what I was able to do in VB6. If I could get access to the
menu name assigned at design time that could work, but I can't see how to do that.
It's not available at run time via the menu item's type.

The sample code in help has hideous If/Then/ElseIf structures like:

If menuitem is mnuFile Then
...
elseif menuitem is mnuEdit then
...
elseif...

But there has to be a better way to uniquely identify a menuitem at run time.

I suppose I could derive a class from MenuItem and define my own tag or other
identifier property, but then I wouldn't be able to use that class in the menu
designer.

Is it possible to discover the specific instance of the menuitem via reflection
somehow?

Nov 20 '05 #1
15 2478
Jeff,

The hashtable creates a table you can look up values based on a key.
The key is an object. Store the value in a hashtable with the key being the
menuitem.

Ken
--------------
"Jeff Mason" <je******@comca st.net> wrote in message
news:57******** *************** *********@4ax.c om...
I have an application where I need to set certain menu items invisible
based on a
user privilege.

We did a sinmlar thing in VB6 and used the menu item's tag property to
assign an
identifier to each menu entry, then used that identifier as an index into
a
collection populated at user login in order to determine the item's
visibility.

Now, for some reason there's no tag property for .NET MenuItems, so I'm
looking for
some way to accomplish what I was able to do in VB6. If I could get
access to the
menu name assigned at design time that could work, but I can't see how to
do that.
It's not available at run time via the menu item's type.

The sample code in help has hideous If/Then/ElseIf structures like:

If menuitem is mnuFile Then
...
elseif menuitem is mnuEdit then
...
elseif...

But there has to be a better way to uniquely identify a menuitem at run
time.

I suppose I could derive a class from MenuItem and define my own tag or
other
identifier property, but then I wouldn't be able to use that class in the
menu
designer.

Is it possible to discover the specific instance of the menuitem via
reflection
somehow?

Nov 20 '05 #2
* Jeff Mason <je******@comca st.net> scripsit:
I have an application where I need to set certain menu items invisible based on a
user privilege.

We did a sinmlar thing in VB6 and used the menu item's tag property to assign an
identifier to each menu entry, then used that identifier as an index into a
collection populated at user login in order to determine the item's visibility.

Now, for some reason there's no tag property for .NET MenuItems, so I'm looking for
some way to accomplish what I was able to do in VB6. If I could get access to the
menu name assigned at design time that could work, but I can't see how to do that.
It's not available at run time via the menu item's type.


<URL:http://groups.google.d e/groups?selm=u0x LOsDCDHA.2316%4 0TK2MSFTNGP10.p hx.gbl>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3
On 30 May 2004 01:32:36 +0200, hi************* **@gmx.at (Herfried K. Wagner [MVP])
wrote:
<URL:http://groups.google.d e/groups?selm=u0x LOsDCDHA.2316%4 0TK2MSFTNGP10.p hx.gbl>
Thank you for your response. Your link suggests I derive a class from MenuItem to
add a property to handle this. But, as I said in my original post:
I suppose I could derive a class from MenuItem and define my own tag or other
identifier property, but then I wouldn't be able to use that class in the menu
designer.


This is a large project with many many menu entries yet to be developed, so the menu
designer is pretty important to me.

Is there another way to identify the menu items in a form?

Nov 20 '05 #4
* Jeff Mason <je******@comca st.net> scripsit:
<URL:http://groups.google.d e/groups?selm=u0x LOsDCDHA.2316%4 0TK2MSFTNGP10.p hx.gbl>


Thank you for your response. Your link suggests I derive a class from MenuItem to
add a property to handle this. But, as I said in my original post:
I suppose I could derive a class from MenuItem and define my own tag or other
identifier property, but then I wouldn't be able to use that class in the menu
designer.


This is a large project with many many menu entries yet to be developed, so the menu
designer is pretty important to me.

Is there another way to identify the menu items in a form?


Well, I don't know about an easy way to do that...

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #5
On Sat, 29 May 2004 19:32:52 -0400, "Ken Tucker [MVP]" <vb***@bellsout h.net> wrote:
Jeff,

The hashtable creates a table you can look up values based on a key.
The key is an object. Store the value in a hashtable with the key being the
menuitem.

Ken


Hi Ken,

Thanks for the response.

Your suggestion implies that the association of "tag" information by menuitem can be
set up only at run time. Since I must be able to persist menu access privilege
information by user in a database, I'm not sure how your technique would apply. Each
user would have access defined for each menu entry, so I'm envisioning a database
table storing {User, <somekindofMenu Identifier>, AccessRights}. At app
startup/logon, then, when I identify the User, I would retrieve his menu access
rights and modify the menu accordingly, i.e. set a given MenuItem visible/invisible
based on the rights. So the problem is in persisting <somekindofMenu Identifier> and
then relating that back to the corresponding MenuItem object.

In VB6 we defined an arbitrary ID value as <somekindofMenu Identifier> and stored it
in the menu's Tag property at design time. At run time, then, it was easy to
identify the particular menu entry by searching for this tag value.

But I see no good way to do the equivalent in .NET :-(

Is there any way to obtain the MenuItem's name by say, reflection?

Nov 20 '05 #6
On 30 May 2004 01:32:36 +0200, hi************* **@gmx.at (Herfried K. Wagner [MVP])
wrote:
<URL:http://groups.google.d e/groups?selm=u0x LOsDCDHA.2316%4 0TK2MSFTNGP10.p hx.gbl>
Thank you for your response. Your link suggests I derive a class from MenuItem to
add a property to handle this. But, as I said in my original post:
I suppose I could derive a class from MenuItem and define my own tag or other
identifier property, but then I wouldn't be able to use that class in the menu
designer.


This is a large project with many many menu entries yet to be developed, so the menu
designer is pretty important to me.

Is there another way to identify the menu items in a form?

Nov 20 '05 #7
* Jeff Mason <je******@comca st.net> scripsit:
<URL:http://groups.google.d e/groups?selm=u0x LOsDCDHA.2316%4 0TK2MSFTNGP10.p hx.gbl>


Thank you for your response. Your link suggests I derive a class from MenuItem to
add a property to handle this. But, as I said in my original post:
I suppose I could derive a class from MenuItem and define my own tag or other
identifier property, but then I wouldn't be able to use that class in the menu
designer.


This is a large project with many many menu entries yet to be developed, so the menu
designer is pretty important to me.

Is there another way to identify the menu items in a form?


Well, I don't know about an easy way to do that...

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #8
On Sat, 29 May 2004 19:32:52 -0400, "Ken Tucker [MVP]" <vb***@bellsout h.net> wrote:
Jeff,

The hashtable creates a table you can look up values based on a key.
The key is an object. Store the value in a hashtable with the key being the
menuitem.

Ken


Hi Ken,

Thanks for the response.

Your suggestion implies that the association of "tag" information by menuitem can be
set up only at run time. Since I must be able to persist menu access privilege
information by user in a database, I'm not sure how your technique would apply. Each
user would have access defined for each menu entry, so I'm envisioning a database
table storing {User, <somekindofMenu Identifier>, AccessRights}. At app
startup/logon, then, when I identify the User, I would retrieve his menu access
rights and modify the menu accordingly, i.e. set a given MenuItem visible/invisible
based on the rights. So the problem is in persisting <somekindofMenu Identifier> and
then relating that back to the corresponding MenuItem object.

In VB6 we defined an arbitrary ID value as <somekindofMenu Identifier> and stored it
in the menu's Tag property at design time. At run time, then, it was easy to
identify the particular menu entry by searching for this tag value.

But I see no good way to do the equivalent in .NET :-(

Is there any way to obtain the MenuItem's name by say, reflection?

Nov 20 '05 #9
How about creating an extender to add an Identifier property to a menu item?
You'll get the extra property and will still be able to use standard
MenuItems.
I'll just write one now and add it to the Menus section on my website.

--
Mick Doherty
http://homepage.ntlworld.com/mdaudi100/index.html
"Jeff Mason" <je******@comca st.net> wrote in message
news:39******** *************** *********@4ax.c om...
On 30 May 2004 01:32:36 +0200, hi************* **@gmx.at (Herfried K. Wagner [MVP]) wrote:
<URL:http://groups.google.de/groups?selm=...K2MSFTNGP10.ph x.gbl>
Thank you for your response. Your link suggests I derive a class from MenuItem to add a property to handle this. But, as I said in my original post:
I suppose I could derive a class from MenuItem and define my own tag or otheridentifier property, but then I wouldn't be able to use that class in the menudesigner.
This is a large project with many many menu entries yet to be developed,

so the menu designer is pretty important to me.

Is there another way to identify the menu items in a form?

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.691 / Virus Database: 452 - Release Date: 26/05/2004
Nov 20 '05 #10

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

Similar topics

9
3678
by: Rakesh | last post by:
Hi, I am able to obtain a MenuItem object's Name property @ design-time, but am not able to get the same @ run- time...why? And since MenuItem doesn't inherit from Control class, it's not even supposed to be available @ design-time right?
4
4994
by: Tony | last post by:
like this, foreach (MenuItem item in this.mainMenu1.MenuItems) { //some code //I want to get the menuitem's name here! } No name property found. please help!
6
6230
by: Claus Holm | last post by:
I'm trying to enable a menuitem in the parent form from a mdichild. Rather than making the menuitems public, I'd go for a public method in the parent form to do the change, but when I call the method from the mdichild, I get this error: C:\MyProjects\Visual Studio Projects\Tournament\Forms\frmLogin.cs(69): The name 'test' does not exist in the class or namespace 'Tournament.frmLogin' frmLogin is the mdichild.
4
1839
by: Jeff Mason | last post by:
I have an application where I need to set certain menu items invisible based on a user privilege. We did a sinmlar thing in VB6 and used the menu item's tag property to assign an identifier to each menu entry, then used that identifier as an index into a collection populated at user login in order to determine the item's visibility. Now, for some reason there's no tag property for .NET MenuItems, so I'm looking for some way to...
6
1546
by: Agnes | last post by:
dim c as controls for each c in me.controls messagebox.show(c.name) next c I found that the menu time didn't show up ?? It didn't belongs to the control in the form ??? I need to Me.mnuXXX.Enabled = false during run-time Anyone know how can do that ??
2
1252
by: Agnes | last post by:
I know how to get the Menuitem's TEXT . BUT I need to get the names , Does anyone know how to do ?? Thanks I try That " For Each FileMenuItem As MenuItem In Me.Menu.menuitem" before
1
2401
by: Michael | last post by:
Hi Everyone, I seem to be having a problem accessing a menuitem on the MDIParent from a child form. From a login (frmSecurity -child form) screen, I need to hide a menuitem based on the users role. The problem is that I can't seem to get access to the menuitem. I can't get it with code like: MDIParent.mnuAdministrator.Visible = true MDIParent is the name of the form I gave. This is also the Startup form (in the project settings) if this...
3
3568
by: Jason Huang | last post by:
Hi, Would someone tell me how to get a MenuItem's Name in a C# Windows Form? Thanks for help. Jason
2
2172
by: polocar | last post by:
Hi, I'm writing a program using Visual C# 2005 Professional Edition, and I was trying to assign multiple MainMenu objects (one by one, of course) to the same Form (let's suppose 2 MainMenu objects). It is possible (and it's my case) that these 2 MainMenu objects use some different MenuItem objects and some identical MenuItem objects. For example, let's assume that: mainMenu1 contains miFile, miEdit, miHelp mainMenu2 contains miFile,...
0
9646
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10795
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10550
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7760
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6957
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5627
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5796
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4427
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 we have to send another system
2
3981
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.