Twenty
Twenty

Reputation: 5901

Get selected items in solution with native interfaces

I am trying to get all selected items in a solution and this with native code. With native code I am referring to code which does not use the DTE.

I checked the documentation and tried to find a suitable solution, however I din't come very far. What I found was the IVsUiHierarchy which contains the ExecCommand method which contains the following.

Commands that act on a specific item within the hierarchy. (If ItemID equals VSITEMID_SELECTION, the command is applied to the selected item or items.)

So I suspect the method they are talking about, is the before mentioned ExecCommand one. For one I am not quite sure how I will get to the IVsHierarchy object from a IVsHierarchy or similar, on the other hand I am not really sure on how to use the ExecCommand method properly. Additionally I am not even quite certain, if this is even the 'right way' of approaching this.

Note: I am searching for a solution which does not contain the following code in this answer.

Upvotes: 0

Views: 105

Answers (1)

Ed Dore
Ed Dore

Reputation: 2109

You can use IVsMonitorSelection.GetCurrentSelection, to identify all the selected items in the solution explorer.

The above will return you an IVsMultItemSelect interface which you can use to invoke IVsMultiItemSelect.GetSelectedItems to retrieve an array of VSITEMSELECTION values.

There are a few extensibilty samples, that utilize GetSelectedItems, you can use as a reference.

Sincerely, Ed Dore

Upvotes: 1

Related Questions