c#FlaUi从另一个程序的DataGridView获取所有值

c#FlaUi从另一个程序的DataGridView获取所有值,c#,flaui,C#,Flaui,我试图从另一个程序的DataGridBox中提取所有值。为此,我使用FlaUi。我做了一个我想要的代码。然而,这是非常缓慢的。有没有一种更快的方法可以使用FlaUi从另一个程序的DataGridView中提取所有值 我的代码: var desktop = automation.GetDesktop(); var window = desktop.FindFirstDescendant(cf => cf.ByName("History: NEWLIFE"))

我试图从另一个程序的DataGridBox中提取所有值。为此,我使用FlaUi。我做了一个我想要的代码。然而,这是非常缓慢的。有没有一种更快的方法可以使用FlaUi从另一个程序的DataGridView中提取所有值

我的代码:

var desktop = automation.GetDesktop();
                var window = desktop.FindFirstDescendant(cf => cf.ByName("History:  NEWLIFE")).AsWindow();
                var table = window.FindFirstDescendant(cf => cf.ByName("DataGridView")).AsDataGridView();

                int rowscount = (table.FindAllChildren(cf => cf.ByProcessId(30572)).Length) - 2;
                // Remove the last row if we have the "add" row

                for (int i = 0; i < rowscount; i++)
                {
                    string string1 = "Row " + i;
                    string string2 = "Symbol Row " + i;

                    var RowX = table.FindFirstDescendant(cf => cf.ByName(string1));
                    var SymbolRowX = RowX.FindFirstDescendant(cf => cf.ByName(string2));
                    SCAN.Add("" + SymbolRowX.Patterns.LegacyIAccessible.Pattern.Value);                    
                }

                var message = string.Join(Environment.NewLine, SCAN);
                MessageBox.Show(message);
var desktop=automation.GetDesktop();
var window=desktop.findfirstdescentant(cf=>cf.ByName(“历史:新生活”)).AsWindow();
var table=window.findfirstdescentant(cf=>cf.ByName(“DataGridView”)).AsDataGridView();
int rowscont=(table.FindAllChildren(cf=>cf.ByProcessId(30572)).Length)-2;
//如果有“添加”行,请删除最后一行
for(int i=0;icf.ByName(string1));
var SymbolRowX=RowX.findfirstdescentant(cf=>cf.ByName(string2));
SCAN.Add(“+SymbolRowX.Patterns.LegacyIAccessible.Pattern.Value”);
}
var message=string.Join(Environment.NewLine,SCAN);
MessageBox.Show(message);

提前感谢

搜索子体非常慢,因为它将遍历树中的所有对象,直到找到所需的控件(或者没有剩下任何控件)。使用网格模式查找所需的单元格或一次获取所有行并循环通过它们可能要快得多

或者,您可以尝试缓存,因为UIA使用进程间调用,这通常比较慢。因此,每个Find方法或value属性都执行这样的调用。如果你有一个大的网格,那么总结起来会很糟糕。对于这种情况,使用UIA缓存是有意义的。 为此,您可以在缓存请求中一次性获得所需的所有内容(表的所有后代和LegacyIAccessible模式),然后使用CachedChildren等循环遍历代码中的这些元素。 在FlaUI wiki上可以找到一个简单的例子:

var grid=.AsGrid();
var cacheRequest=new cacheRequest();
cacheRequest.TreeScope=TreeScope.substands;
Add(Automation.PropertyLibrary.Element.Name);
使用(cacheRequest.Activate())
{
变量行=_grid.rows;
foreach(行中的变量行)
{
foreach(行中的var单元格。CachedChildren)
{
Console.WriteLine(cell.Name);
}
}
}
var grid = <FindGrid>.AsGrid();
var cacheRequest = new CacheRequest();
cacheRequest.TreeScope = TreeScope.Descendants;
cacheRequest.Add(Automation.PropertyLibrary.Element.Name);
using (cacheRequest.Activate())
{
    var rows = _grid.Rows;
    foreach (var row in rows)
    {
        foreach (var cell in row.CachedChildren)
        {
            Console.WriteLine(cell.Name);
        }
    }
}