473,756 Members | 7,817 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to find a MenuItem's name

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
4 1831
Hi, Jeff

You can use same approach, which worked in VB6. While MenuItem doesn't
provide Tag property originally, you can always derive your TaggedMenuItem,
which has this property, and use it instead of MenuItem

Simple sample

class TaggedMenuItem : MenuItem {
public object Tag {
get ...
set ...
}
}

HTH
Alex

"Jeff Mason" <je******@comca st.net> wrote in message
news:r3******** *************** *********@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
On Sat, 29 May 2004 19:17:51 -0400, "AlexS" <sa***********@ SPAMsympaticoPL EASE.ca>
wrote:
Hi, Jeff

You can use same approach, which worked in VB6. While MenuItem doesn't
provide Tag property originally, you can always derive your TaggedMenuItem,
which has this property, and use it instead of MenuItem

Simple sample

class TaggedMenuItem : MenuItem {
public object Tag {
get ...
set ...
}
}

HTH
Alex
Thank you for your response. 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.


so I was aware of this technique.

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, perhaps via refelction, to identify the menu items in a form?

Nov 20 '05 #3
On Sat, 29 May 2004 19:17:51 -0400, "AlexS" <sa***********@ SPAMsympaticoPL EASE.ca>
wrote:
Hi, Jeff

You can use same approach, which worked in VB6. While MenuItem doesn't
provide Tag property originally, you can always derive your TaggedMenuItem,
which has this property, and use it instead of MenuItem

Simple sample

class TaggedMenuItem : MenuItem {
public object Tag {
get ...
set ...
}
}

HTH
Alex
Thank you for your response. 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.


so I was aware of this technique.

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, perhaps via refelction, to identify the menu items in a form?

Nov 20 '05 #4
Could you just use some schema with the name of the menu item?

Also you could do a find and replace with your derived class name on the
menuitem. That would solve your problem with not being able to use the
menu designer.

"Jeff Mason" <je******@comca st.net> wrote in message
news:qh******** *************** *********@4ax.c om...
On Sat, 29 May 2004 19:17:51 -0400, "AlexS" <sa***********@ SPAMsympaticoPL EASE.ca> wrote:
Hi, Jeff

You can use same approach, which worked in VB6. While MenuItem doesn't
provide Tag property originally, you can always derive your TaggedMenuItem,which has this property, and use it instead of MenuItem

Simple sample

class TaggedMenuItem : MenuItem {
public object Tag {
get ...
set ...
}
}

HTH
Alex
Thank you for your response. 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.


so I was aware of this technique.

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, perhaps via refelction, to identify the menu items in a form?


Nov 20 '05 #5

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

Similar topics

9
3674
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
4988
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
6224
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.
6
1330
by: Eric Sabine | last post by:
Basically, the following code creates a menuItem array and tries to use it twice. In the following piece of code, only the line that appears second gets used. The first becomes ignored presumably when the second is run. Me.mnuFile.MenuItems.AddRange(myMenu) Me.ContextMenu1.MenuItems.AddRange(myMenu) Below I've included just enough code to see it as an example. Can someone explain to me why this happens?
15
2473
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...
1
7285
by: Rom | last post by:
Hi, How can I find a record in a dataset. I have 1 textbox name txtfind. my sql statement should be like this.."select * from employees where emp_id= txtfind.text" then if found it should bind the fields to the corresponding textboxes on the form.
6
1543
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
1247
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
2396
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...
0
9275
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
10040
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...
0
9713
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 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...
0
8713
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6534
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
5142
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
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3806
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
3
2666
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.