Solved

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

Posted on 2014-01-16
1
246 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

705 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