?
Solved

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

Posted on 2014-01-16
1
Medium Priority
?
248 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 1500 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
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 …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

765 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