locked
Accessing Right Click event of CommandBar in SSMS 2008 R2 RRS feed

  • Question

  • Hi I'm writing an addin into SSMS 2008 R2. Most of the functionality will be accessed via the right click context menu of the 'SQL Results Grid Tab'. I've been able to add meu items into this context menu, but the menu items I want in the menu will be different depending on what was clicked. So what I want, is when the right mouse button is clicked, it calls a method of mine where I can add my items into the menu before it is shown. The first block of code below is what I have been using to add menu items into the relevant conext menu - and it works fine. Block 2 is how I believe I need to add a click event handler into the relevant command bar. It compiles, but clicking the right mouse does not show my message box, it bring up the context menu. Any ideas? Thanks Rod /// Block 1 /// Microsoft.VisualStudio.CommandBars.CommandBar sqlQueryGridPane = ((CommandBars)_applicationObject.CommandBars)["SQL Results Grid Tab Context"]; CommandBarPopup cmdBarControl2 = (CommandBarPopup)sqlQueryGridPane.Controls.Add(MsoControlType.msoControlPopup, Type.Missing, Type.Missing, Type.Missing, true); cmdBarControl2.Caption = "Sub menu"; cmdBarControl2.BeginGroup = true; CommandBarControl oControl = cmdBarControl2.Controls.Add(MsoControlType.msoControlButton, Type.Missing, Type.Missing, 1, true); oControl.Caption = "Hello"; /// End Block 1 /// /// Block 2 /// Microsoft.VisualStudio.CommandBars.CommandBar sqlQueryGridPane = ((CommandBars)_applicationObject.CommandBars)["SQL Results Grid Tab Context"]; CommandBarEvents mGotoDeclarationItemHandler = (CommandBarEvents)_applicationObject.Events.get_CommandBarEvents(sqlQueryGridPane); mGotoDeclarationItemHandler.Click += new _dispCommandBarControlEvents_ClickEventHandler(mGotoDeclarationItemHandler_Click); public void mGotoDeclarationItemHandler_Click( Object CommandBarControl, ref bool Handled, ref bool CancelDefault) { MessageBox.Show("Yay"); } /// End Block 2///
    Thursday, February 17, 2011 9:40 AM

Answers

  • The click handler is about left click (execution), not right click, also there are other ways to bring up a context menu (context menu key, Alt-Shift-F10) without using the mouse.  Since you talk about wanting to hide items the better way to go is to implement IDtCommandTarget and then inside there determine if each command should be visible or not. If you need to determine what is selected you can probably use the normal selection context / UI context concepts in VS, though I don't know much about SSMS extensibility and how much they expose from their own bits or if what is exposed would let you figure out 'what was clicked'.

    Ryan

    • Proposed as answer by Victor_Chen Friday, February 25, 2011 2:58 AM
    • Marked as answer by Victor_Chen Friday, February 25, 2011 7:56 AM
    Thursday, February 17, 2011 5:01 PM

All replies

  • The click handler is about left click (execution), not right click, also there are other ways to bring up a context menu (context menu key, Alt-Shift-F10) without using the mouse.  Since you talk about wanting to hide items the better way to go is to implement IDtCommandTarget and then inside there determine if each command should be visible or not. If you need to determine what is selected you can probably use the normal selection context / UI context concepts in VS, though I don't know much about SSMS extensibility and how much they expose from their own bits or if what is exposed would let you figure out 'what was clicked'.

    Ryan

    • Proposed as answer by Victor_Chen Friday, February 25, 2011 2:58 AM
    • Marked as answer by Victor_Chen Friday, February 25, 2011 7:56 AM
    Thursday, February 17, 2011 5:01 PM
  • Hi Rodj,

     

    Is it resolved?

    If not, could you please let me know your situation,

    I'm glad to help.


    Ziwei Chen [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, February 24, 2011 7:14 AM