Solved

Need to Programatically Find Controls With ContextMenuStrips Containing "Run" MenuItem, Then Initiate Addhandler Call to SubRoutine

Posted on 2014-01-16
1
242 Views
Last Modified: 2014-01-17
I am adding elements of each control's contextmenustrips using the code below

sender.Items.AddRange(New ToolStripItem() {ctmsview, ctmsrun, ctmsdelete})

where for example, the ctmsrun text is:

ctmsrun.Text = "Run"

If a user right clicks on a control's contextmenustrip and selects "Run", then the addhandler runs the ctmsrun routine.   Very important: once inside the ctmsrun routine, the source control's name is used to determine what to do.

Question is, what's the best way to pick off all the control's whose contextmenustrip have a "Run" menu item, and then fire the ctmsrun routine as if the user right clicked on sequential form controls (there is a defined sequence of the controls to be run, and that is known)?  

So the question is: Given many Form controls with contextmenustrips (not all controls have a contextmenustrip) what's the best way to identify those with a either "Run" as the text or ctmsrun used with the addhandler (to actually fire the subroutine).  

My guess is to just loop through all controls, identify which controls have a contextmenustrip, and then find out if there is a ctsmrun command or "Run" text in the menu item text?  The call ctmsrun somehow for that source control?

By the way, once inside the ctmsrun routine, I use the following to obtain the name of the parent control of the specific contextmenustrip that was right-clicked:  

 Dim myItem As ToolStripMenuItem = CType(sender, ToolStripMenuItem)
 Dim cms As ContextMenuStrip = CType(myItem.Owner, ContextMenuStrip)
 cmssourcecontrolname = cms.Name

Open in new window

   

However, I need to find out what the menu items are within the contextmenustrip.
0
Comment
Question by:lep1
1 Comment
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 39788546
The ContextMenuStrip has the Items property, which are the menu items.  You should be able to loop through the items to get what you need.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Visual Studio installation 5 36
Hovering effect 9 29
Form design in vb.net 7 18
What .NET website keeps me current? 9 29
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now