Events with Programmatically-Created Context Menu Items

M

Matt Harvey

Let's say that I populate a context menu with commands from a database
table using a loop, and that these commands and their number can change
at any time. Is there a way to dynamically have events to fire when
clicking one of the items, using generic code?

For instance, let's say that these are the items on my context menu from
the database:

COMMAND1
COMMAND2
COMMAND3

Now let's say that I haven't actually coded a click event for any of
these, but want to use a generic click event so that if I click
"COMMAND3", the menuitem that's been clicked is passed to a function
containing a switch or something like that.

Is this possible?
 
G

Guest

You can certainly use the same "Generic" eventhandler for all of them, and
inside its code you can determine "which one" it was that sent the event via
the "sender" argument.

Peter
 
M

Matt Harvey

Peter said:
You can certainly use the same "Generic" eventhandler for all of them, and
inside its code you can determine "which one" it was that sent the event via
the "sender" argument.

Peter
Can anyone point me to a resource as to how to do this?

Thanks,
Matt
 
S

Stoitcho Goutsev \(100\)

Matt,

No, there is no generic event for the menu items.

What Peter suggested is to add event handlers to all menu items upon
creation. All the delegates will point to the same method. Inside the method
you can use the *sender* parameter to determine the menu item that was
clicked.


If there is something not clear don't hesitate to post it.
 

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