简体   繁体   中英

How to get selected items in Visual Studio ErrorWindow?

How to get selected items from Visual studio error window? I tried below code

        DTE2 dte2 = Package.GetGlobalService(typeof(DTE)) as DTE2;

        dte2.ExecuteCommand("View.ErrorList", " ");
        
        IList<string> errors = new List<string>();
        // Can get complete list.
        ErrorList errorList = dte2.ToolWindows.ErrorList;

        // Below line does not work and always returns null. 
        var item = dte2.ToolWindows.ErrorList.SelectedItems;

Is there any other way to get the selected items?

You can use the following code:

        if (await this.package.GetServiceAsync(typeof(SVsErrorList)) is IVsTaskList2 tasks)
        {
            tasks.EnumSelectedItems(out IVsEnumTaskItems itemsEnum);

Copied from Matt Lacey's ErrorHelper extension .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM