从插件以编程方式访问visual studio查询结果窗格
本文关键字:查询 studio 结果 visual 访问 插件 编程 方式 | 更新日期: 2023-09-27 18:15:53
是否有办法从插件访问visual studio的查询结果窗格?
我不是指从菜单-数据-交易SQL编辑器-新查询查询窗口。我想从服务器探索-扩展一些数据库-扩展表,右键单击表并选择新的查询。在选择将包括哪些表之后,检查几个列并选择执行。新窗口将打开。那个窗口是文档类,我知道,但不能从那个类获得控件或窗格甚至面板的内容。在底部,您可以看到一个包含行和列的窗格。
如果可能的话,我需要访问窗格或网格控件。或者更好地通过反射来检索查询结果窗口中选定单元格的单元格值?
我已经为VS构建了插件,但是很难从网格中检索单元格的值。尝试使用反射,但无法找到问题的底部,甚至无法找到此窗格或网格控件的位置
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.
}
}
}