Server Explorer, which node was right-clicked?

I have added a context menu to the Server explorer using an add-in. I want to be able to get the type of node that was right-clicked on when the context menu appears, e.g. a Database, table, stored procdeure, etc...

I know how to get the UIHierarchy object from the Server Explorer Window object, but that is as far as I can get.

Thanks in advance!



Answer this question

Server Explorer, which node was right-clicked?

  • k1dugar

    I've gotten this all working from the perspective of a DDEX data provider, but things are slightly different for you. From my code, I have a class that implements DataViewCommandHandler and can extend the context menu via my provider's DataViewSupport XML code combined with my class.

    You on the other hand, need to get the IVsUIHierarchy interface of the server explorer tree instead, and can then call the GetProperty() method.

    GetProperty() takes an itemid, and a propertyid (which may be 203 for your purposes) and will return an object. You may have to play around with propertyid's to figure out which one gets you the information you want.

    For propertyid 203, if you query for information about a table, the array will contain {"database", "schema", "table"}. A column would return {"database", "schema", "table", "column"}. Basically the restrictions you'd pass to a DbConnection.GetSchema() call.

    Getting the DataConnection to which that object belongs is another issue though.

    Robert


  • Philip Lee

    This macro will find the selected item, from that you can walk up the list of items to find the exact path of the item added. However, there are no direct mappings from the item to a DB table, etc, once you find the path of the item you will need to connect to that object manually

    Sub SelItem()

    Dim uihier As UIHierarchy

    Dim uihieritem As UIHierarchyItem

    uihier = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindServerExplorer).Object

    uihieritem = uihier.SelectedItems(0)

    End Sub

    Craig



  • zhonglixunni

    I'm stuck on this same issue. I am able to find the name of the UIHierarchy item, but unable to find the object type. (I want to only display a context menu option for database tables from within the server explorer.) What do you mean by "once you find the path of the item you will need to connect to that object manually"

    Thanks much


  • Server Explorer, which node was right-clicked?