How to get all properties of selected item in Visual Studio ErrorWindow?

80 Views Asked by At

Does anyone know how to get this data from the Error window? I followed this example, which allows me to obtain the selected error message. However, that only obtains the Description column. I can also get the Line Number and Document. However, I want to also get the text of the Error Code - and I can't find how to get the Code.

enter image description here

In the above example, I also want to get 'CS1002'.

I also tried this code, which gives me more fields (but not the Code field), but does not get me the selected item - it is a list of all items in the Error List window...

    EnvDTE80.DTE2 dte = (EnvDTE80.DTE2)Package.GetGlobalService(typeof(SDTE));
    Assumes.Present(dte);
    ErrorList errorList = dte.ToolWindows.ErrorList;
    for (int i = 1; i <= errorList.ErrorItems.Count; i++)
    {
        var itm = (ErrorItem)errorList.ErrorItems.Item(i);
        MessageBox.Show(itm.Description);
    }
1

There are 1 best solutions below

0
Jay Imerman On

Got it! This worked, you just have to know the proper column names to search for.

    EnvDTE80.DTE2 dte = (EnvDTE80.DTE2)Package.GetGlobalService(typeof(SDTE));
    var errorList = dte.ToolWindows.ErrorList as IErrorList;
    var selected = errorList.TableControl.SelectedEntry;
    object code = null;
    object desc = null;
    if (selected != null)
    {
        selected.TryGetValue("errorcode", out code);
        selected.TryGetValue("text", out desc);
    }