MenuItem missing Tag field.. why?

G

Guest

Hi,

When creating a popup menu I find it rather difficult to provide the
eventhandler for the MenuItem with enough information. My actual problem is
that I create a popup menu with a list of objects of which one, by clicking
the item, must be assinged to another object. I use the same eventhandler for
all the menuitems in the popup menu as the objects listed in the popup menu
is of arbitrary length. To correlate the 'sender' menuitem in my eventhandler
with its corresponding object, I use menuitem.Index to get the position of
the menuitem in the popup window and then can deduct the position of the
corresponding object in an arraylist. It seems wrong to to it this way, I'm
so much missing the Tag field for menuitems....

Having any suggestions to a better way, please PLEASE reply on this.

Than you very much. Best regards Jesper, Denmark.
 
H

hOSAM

Hi Jesper,

I am not so into UI programming, but as a first thought, you make your own
derived version of MenuItem, and then add a property to it for accessing the
object.
Is that a valid solution for you?.
 
R

Rakesh Rajan

Hi Jesper,

The MenuItem class doen not derive from the Control class and hence doesn't
have the Tag property.

Though extending the menuitem class is a solution, i don't know whether this
would affect usability thru the designer in any way.
Another solution would be to use the Hashtable to store the text of the menu
items and then find out which menu item was invoked - yes it isn't very
'graceful' :).

HTH
- Rakesh Rajan
 
P

Paul E Collins

Rakesh Rajan said:
Though extending the menuitem class is a solution, i don't
know whether this would affect usability thru the designer

It would. A newly written inherited class isn't automatically usable
in the Designer.
Another solution would be to use the Hashtable to store
the text of the menu items and then find out which menu
item was invoked - yes it isn't very 'graceful' :).

Menu items can share captions, or change their captions at run time,
so it would be smarter to use the MenuItems themselves (reference
types) as keys in the HashTable.

P.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top