문제

I'm creating a Visual Studio add-in and when I select data connection node in Server explorer window (or data table or data field) is there a way to get property values from Properties window shown in visual studio using EnvDTE?

I need to get these values from these fields: Connection string, Provider, Data type, Is Identity, etc.

thnx in advance

도움이 되었습니까?

해결책

Here is some sample code that demonstrate how to access the selection in the property grid. Note there can be multiple objects selected, not only one:

IVsMonitorSelection selection = (IVsMonitorSelection)yourSite.GetService(typeof(SVsShellMonitorSelection)); // or yourPackage.GetGlobalService
IVsMultiItemSelect ms;
IntPtr h;
IntPtr pp;
uint itemid;

selection.GetCurrentSelection(out h, out itemid, out ms, out pp);
if (pp != IntPtr.Zero)
{
    try
    {
        ISelectionContainer container = Marshal.GetObjectForIUnknown(pp) as ISelectionContainer;
        if (container != null)
        {
            uint count;
            container.CountObjects((uint)Microsoft.VisualStudio.Shell.Interop.Constants.GETOBJS_SELECTED, out count);
            if (count == 1)
            {
                object[] objs = new object[1];
                container.GetObjects((uint)Microsoft.VisualStudio.Shell.Interop.Constants.GETOBJS_SELECTED, 1, objs);
                object selection = objs[0]; // selection is here
            }
        }
    }
    finally
    {
        Marshal.Release(pp);
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top