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? 15 2473
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?
* 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/>
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?
* 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/>
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?
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?
* 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/>
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?
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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?
|
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!
|
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.
|
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...
|
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 ??
| |
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
|
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...
|
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
|
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,...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| | |