473,395 Members | 1,885 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.

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 2225
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Marek Mand | last post by:
How to use generated keyboard events? What I am trying here to do is in onkeyup event handler http://www.hot.ee/idaliiga/braggart/createEventTest.htm generate a (shift)TAB keydown so the...
2
by: Bryan Glennon | last post by:
I've been mucking around with databinding & I am seeing something I can't explain... I have a collection (PersonList) that inherits from CollectionBase and implements IBindingList. It contains...
0
by: Josef Meile | last post by:
Hi I wanted to programmatically disable events like SelectedIndexChanged without using a boolean flag, which indeed I find a quick and dirty solution. So, I found a piece of code that do this...
5
by: Patrick | last post by:
Hello I have the following problem. I have an aspx Page. This page contains an ASP-Table Object. So in that table, I have a linkbutton. So, I can't edit the event of that button trough the...
3
by: Luis E Valencia | last post by:
I have a table that says for example 01/05/2004 Party IIsadpaks 01/06/2004 Party 2394923423 A events table. I want to make a calendar and that the days that are events are inbold and with...
5
by: snesbit | last post by:
If a screen is made up of several user controls and those user controls contain various packaged or standard controls such as a grid, how do you raise both standard and custom events from the user...
2
by: bretth | last post by:
In a VB.Net Windows Forms application, I have a user control that handles mouse events. Another section of code programmatically adds a label to the control. I would like label to ignore all...
1
by: Valentin Kotelnitski | last post by:
Hello! I have got an application (some part of which is written by me). There is a control on which events are blocked (not processed) (do not work OnPaint, OnMouseDown, OnMouseOver and other...
5
by: Richard Maher | last post by:
Hi, Here I mean "User" in the Programmer or Javascript sense. I merely wish to programmatically trigger an Event. It would be absolutely fantastic if there was a (Form level?) ONUSEREVENT() and...
0
by: erkbiz | last post by:
Hello, I have an event that I defined with a delegate. When I bind this event to a button and place the event prior to calling base.OnLoad(e) which is called prior to if (!PostBack) the Event...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.