[英]C# DataGridView get values from another column if cells is selected
[英]c# FlaUi get all the Values from DataGridView of another program
我正在嘗試從另一個程序的 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);
先感謝您
搜索后代非常緩慢,因為它會遍歷樹中的所有對象,直到找到所需的控件(或者沒有控件剩余)。 使用網格模式查找所需的單元格或一次獲取所有行並循環遍歷它們可能會快得多。
或者,您可以嘗試緩存,因為 UIA 使用通常很慢的進程間調用。 所以每個 Find 方法或 value 屬性都會執行這樣的調用。 如果你有一個很大的網格,那總結起來會很糟糕。 對於這種情況,使用 UIA 緩存是有意義的。 為此,您將在緩存請求中一次性獲得所需的一切(表的所有后代和 LegacyIAccessible 模式),然后使用 CachedChildren 等循環遍歷代碼中的這些元素。 一個簡單的例子可以在https://github.com/FlaUI/FlaUI/wiki/Caching的 FlaUI wiki 中找到:
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);
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.