471,310 Members | 1,211 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Events with Programmatically-Created Context Menu Items

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?

Feb 16 '06 #1
3 2166
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
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Matt Harvey" wrote:
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?

Feb 16 '06 #2
Peter Bromberg [C# MVP] wrote:
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
Feb 16 '06 #3
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.
--
HTH
Stoitcho Goutsev (100)

"Matt Harvey" <ri******@gmail.com> wrote in message
news:uj**************@TK2MSFTNGP15.phx.gbl...
Peter Bromberg [C# MVP] wrote:
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

Feb 16 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Bryan Glennon | last post: by
reply views Thread by Josef Meile | last post: by
3 posts views Thread by Luis E Valencia | last post: by
1 post views Thread by Valentin Kotelnitski | last post: by
5 posts views Thread by Richard Maher | last post: by

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.