473,395 Members | 1,613 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 1790
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******@comcast.net> wrote in message
news:r3********************************@4ax.com...
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***********@SPAMsympaticoPLEASE.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***********@SPAMsympaticoPLEASE.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******@comcast.net> wrote in message
news:qh********************************@4ax.com...
On Sat, 29 May 2004 19:17:51 -0400, "AlexS" <sa***********@SPAMsympaticoPLEASE.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
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...
4
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
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...
6
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...
15
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...
1
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...
6
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...
2
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
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
0
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,...
0
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...
0
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,...

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.