Thanks Iain Yep, you are right on track with my problem. I would have liked to use the standard menu (have 9 already developed applications I have to do this for and don't really want to change the current menu's to an inherited one) I hoped I would be able to use reflection to cycle through the local variables in the form, and maybe use the .Equals operator compare to the Sender parameter and identify the correct local variable. If I can't get that up and running I will need to make an inherited item
Thanks JC -----Original Message----- From: Iain Smallwood [mailto:[EMAIL PROTECTED]] Sent: 13 August 2002 03:37 PM To: [EMAIL PROTECTED] Subject: Re: [ADVANCED-DOTNET] Name of MenuItem through Reflection Doing this kind of thing can be helpful. Basically when you create the menuitem you give it a unique identifier of your chosen type (here an integer based on a database primary key but can be a string or a form ref or an elephant). Note my scoping is sloppy. Friend Class DataMenuItem Inherits MenuItem 'just a menu item that retains a PK reference from creation Public Sub New(ByVal intItemID As Integer) DatabaseID = intItemID End Sub Friend DatabaseID As Integer End Class Whack a new menuitem on like: MyItem = New DataMenuItem(MyInteger) MyItem .Text = "Blah" MyMenu.MenuItems.Add(MyItem) Then you can CType the sender to a DataMenuItem in your click event no worries and get your desired ID out. Hope I have grasped your issue OK! Cheers, Iain -----Original Message----- From: JC Oberholzer [mailto:[EMAIL PROTECTED]] Sent: 13 August 2002 13:41 To: [EMAIL PROTECTED] Subject: [ADVANCED-DOTNET] Name of MenuItem through Reflection I need to extract the name of a menuitem at runtime using reflection, but it does not have a name property or any custom property which seems appropriate! The situation is: I set up the security for the controls on the form dynamically from a db in the backend using the names of the controls on the form. Works well for everything, except the menu's, as these are not in the controls collection. When a menuitem recieves the "Click" event, I can identify the menuItem by using the event parameter Sender. A MenuItem does not have a Name property however, so I'm back to square one! I tried to extract the name of the local variable that defines the instance (private withevents mymenu as ....), but am struggling to get this. Can anyone help me to extract anything unique per menu item (which is human readable as well) or maybe help me cycle through the local variables on the form (to compare it to the Sender object in the click event) Thanks JC Oberholzer You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com. Disclaimer This message may contain information which is legally privileged and/or confidential. If you are not the intended recipient, you are hereby notified that any unauthorised disclosure, copying, distribution or use of this information is strictly prohibited. Such notification not withstanding, any comments or opinions expressed are those of the originator, not of Taylor Made Computer Solutions, unless otherwise explicitly stated. You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com. The views expressed in this e-mail are, unless otherwise stated, those of the author and not of SDT or its management. The information is confidential and is intended solely for the addressee. All reasonable steps are taken to ensure the accuracy, integrity and confidentiality of information. No liability or responsibility is accepted if information is corrupted or does not reach its intended destination. This e-mail message has been scanned for viruses and cleared. You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.