I would like to get the array of the selected tab objects programmatically as the selection below:
I could only find the way to get the array of selected files in the Solution Explorer:
But it is not that array that I need.
Does anyone know how to get the array of the selected tabs in C#?
The tabs in Visual Studio represent open documents; so you may want to iterate over the document collection instead, that is accessible via the Documents
property of the DTE
instance. See https://learn.microsoft.com/en-us/dotnet/api/envdte._dte.documents?view=visualstudiosdk-2017#EnvDTE__DTE_Documents for further information.
Each Document
returned by Documents
collection allows us to find related windows (those are usually document-windows, but not tool-windows); see https://learn.microsoft.com/en-us/dotnet/api/envdte.document.windows?view=visualstudiosdk-2017 for further information about objects returned by the Windows
property.
The Window
class has properties that might be suitable, for whatever you wanna do with it; for instance ask for its caption, visibility, type, handle, etc.., but I am not sure whether it is possible to determine or derive the information whether the document window´s tab (or document itself) is selected, or not.
As an alternative, you can also use the RunningDocumentTable
service to iterate open documents; see https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.shell.runningdocumenttable?view=visualstudiosdk-2017