Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6390011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:28:29+00:00 2026-05-25T03:28:29+00:00

I am trying to create an additional menu item for the Project and Solutions

  • 0

I am trying to create an additional menu item for the “Project and Solutions Context Menus>Solution” menu. However, I wanted this context menu to appear ONLY when a certain solution was opened, otherwise I don’t want it to show. I figured I could use the MACROS within the Visual Studio IDE. There are events that run on the opening of solutions & projects, etc.

My question is, can I create the Context Menu I want programatically, point it to the MACRO I want it to run, and then programatically attach it to the CONTEXT menu inside the IDE that I want to display it in?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T03:28:29+00:00Added an answer on May 25, 2026 at 3:28 am

    I found the answer to my question. I used the following code to create the menu items I needed:

    Private WithEvents _objSolutionExplorer_ContextMenu_ItemHandler As EnvDTE.CommandBarEvents
    Private _objHash_ContextMenuItemHandlers As New Hashtable
    
    Private Function CreateContextMenuButtonItem(ByVal p_objMenuItem As Object, ByVal p_strMenuItemCaption As String) As CommandBarButton
        '************************************************************************
        ' Procedure/Function: CreateContextMenuButtonItem()
        ' Author: Ben Santiago
        ' Created On: 08/18/2011
        ' Description:
        '       Creates specified MenuButton item.
        '************************************************************************
    
        '***************************************
        ' Initialize Variables
        '***************************************
        Dim objMenuButton As CommandBarButton
        Dim objClickEventHandler As EnvDTE.CommandBarEvents
    
        '***************************************
        ' If MenuItem Exists, Delete It
        '***************************************
        For intCounter As Integer = 1 To p_objMenuItem.Controls.Count
            If p_objMenuItem.Controls.Item(intCounter).Caption = p_strMenuItemCaption Then
                p_objMenuItem.Controls.Item(intCounter).Delete()
                Exit For
            End If
        Next
        If EnvironmentEvents._objHash_ContextMenuItemHandlers.Contains(p_strMenuItemCaption) Then
            EnvironmentEvents._objHash_ContextMenuItemHandlers.Remove(p_strMenuItemCaption)
        End If
    
        '***************************************
        ' Create New Menu Item w/ Click Event Handling
        '***************************************
        objNewMenuItem = p_objMenuItem.Controls.Add(MsoControlType.msoControlButton, System.Reflection.Missing.Value, System.Reflection.Missing.Value, 1, True)
        objNewMenuItem.Caption = p_strMenuItemCaption
        objClickEventHandler = DTE.Events.CommandBarEvents(objNewMenuItem)
        AddHandler objClickEventHandler.Click, AddressOf TestScoring_objSolutionExplorer_ContextMenu_ItemHandler_Click
        If EnvironmentEvents._objHash_ContextMenuItemHandlers.Contains(p_strMenuItemCaption) Then
            EnvironmentEvents._objHash_ContextMenuItemHandlers.Remove(p_strMenuItemCaption)
        End If
        EnvironmentEvents._objHash_ContextMenuItemHandlers.Add(p_strMenuItemCaption, objClickEventHandler)
    
        '***************************************
        ' Return Reference To MenuButton Item
        '***************************************
        Return objNewMenuItem
    End Function
    
    Private Function CreateContextMenuPopupItem(ByVal p_strCommandBarName As String, ByVal p_strMenuCaption As String) As CommandBarPopup
        '************************************************************************
        ' Procedure/Function: CreateContextMenuPopupItem()
        ' Author: Ben Santiago
        ' Created On: 08/18/2011
        ' Description:
        '       Creates specified MenuPopup item.
        '************************************************************************
    
        '***************************************
        ' Initialize Variables
        '***************************************
        Dim objCommandBar As CommandBar = DTE.CommandBars(p_strCommandBarName)
        Dim objMenuPopup As CommandBarPopup
    
        '***************************************
        ' Search For Existing ContextMenuPopup
        '***************************************
        For intCounter As Integer = 1 To objCommandBar.Controls.Count
            If objCommandBar.Controls.Item(intCounter).Caption = p_strMenuCaption Then
                objMenuPopup = objCommandBar.Controls.Item(intCounter)
                Exit For
            End If
        Next
    
        If objMenuPopup Is Nothing Then
            '***************************************
            ' Create Menu If Needed
            '***************************************
            objMenuPopup = objCommandBar.Controls.Add(MsoControlType.msoControlPopup, System.Reflection.Missing.Value, System.Reflection.Missing.Value, 1, True)
            objMenuPopup.Caption = p_strMenuCaption
        Else
            '***************************************
            ' Delete All Child Menu Items
            '***************************************
            For intCounter As Integer = objMenuPopup.Controls.Count To 1 Step -1
                If EnvironmentEvents._objHash_ContextMenuItemHandlers.Contains(objMenuPopup.Controls.Item(intCounter).Caption) Then
                    EnvironmentEvents._objHash_ContextMenuItemHandlers.Remove(objMenuPopup.Controls.Item(intCounter).Caption)
                End If
                objMenuPopup.Controls.Item(intCounter).Delete()
            Next
        End If
    
        '***************************************
        ' Return Reference To MenuPopup Item
        '***************************************
        Return objMenuPopup
    End Function 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a drupal 6 menu tree with additional attributes to
I'm trying to create a website for myself and just ran into this issue:
I am trying to create a value template class, where additional properties can be
I'm trying to create a single page form to create a 'work item'. One
I have been trying to create a Spring project that uses MyBatis for the
Im trying to create an additional function for jqGrid to simplify adding JSON data
In trying to create better, more consistent conventions I wanted to get feedback on
I am trying to create a custom profile to add additional fields to django-registration
I'm trying to figure out how to create additional calculated properties that are exposed
I'm trying to create an interface that requires additional methods on top of IEvent,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.