1

有没有办法从 Addin 访问 Visual Studio 的查询结果窗格?

我不是指来自菜单 - 数据 - 事务 SQL 编辑器 - 新查询的查询窗口。我正在考虑从服务器探索-扩展一些数据库-扩展表,右键单击表并选择新查询。选择将包含哪些表后,检查几列并选择执行。新窗口将打开。该窗口是我知道的 Document 类,但无法从该类中获取控件或窗格甚至面板的内容。在底部,您可以看到一个包含行和列的窗格。

如果可能,我需要访问该窗格或网格控件。或者甚至更好地通过反射检索该查询结果窗口中选定单元格的单元格值?

我已经为 VS 构建了插件,但是无法从该网格中检索单元格的值。尝试了反射,但无法深入了解此窗格或网格控件所在或什至所在的问题。

4

1 回答 1

0
    private static IEnumerable<IntPtr> GetChildWindows(IntPtr parent)
    {
        List<IntPtr> result = new List<IntPtr>();
        GCHandle listHandle = GCHandle.Alloc(result);
        try
        {
            NativeMethods.EnumWindowProc childProc = new NativeMethods.EnumWindowProc(EnumWindow);
            NativeMethods.EnumChildWindows(parent, childProc, GCHandle.ToIntPtr(listHandle));
        }
        finally
        {
            if(listHandle.IsAllocated)
            {
                listHandle.Free();
            }
        }

        return result;
    }

    /// <summary>
    /// Callback method to be used when enumerating windows.
    /// </summary>
    /// <param name="handle">Handle of the next window</param>
    /// <param name="pointer">Pointer to a GCHandle that holds a reference to the list to fill</param>
    /// <returns>True to continue the enumeration, false to bail</returns>
    private static bool EnumWindow(IntPtr handle, IntPtr pointer)
    {
        GCHandle gch = GCHandle.FromIntPtr(pointer);
        List<IntPtr> list = gch.Target as List<IntPtr>;
        if(list == null)
        {
            throw new InvalidCastException("GCHandle Target could not be cast as List<IntPtr>");
        }

        list.Add(handle);

        // You can modify this to check to see if you want to cancel the operation, then return a null here
        return true;
    }

private DataGridView Grid()
{
IEnumerable<IntPtr> a = GetChildWindows(handle);
            foreach(IntPtr b in a)
        {
            Control c = Control.FromHandle(b);
            if(c == null)
            {
                continue;
            }

            try
            {
                if(c.Name != "DataGridView")
                {
                    continue;
                }

                DataGridView dv = c as DataGridView;
                if(dv != null)
                {
                    return dv;
                }
            }
            catch
            {
                // It is safe to suppress errors here.
            }
        }

}

于 2013-06-06T11:53:37.623 回答