Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting full contents of a Datagrid using UIAutomation
    primarykey
    data
    text
    <p>I have need to retrieve all of the items in a Datagrid from an external application using UIAutomation. Currently, I can only retrieve (and view in UISpy) the visible items. Is there a way to cache all of the items in the Datagrid and then pull them? Here's the code:</p> <pre><code>static public ObservableCollection&lt;Login&gt; GetLogins() { ObservableCollection&lt;Login&gt; returnLogins = new ObservableCollection&lt;Login&gt;(); var id = System.Diagnostics.Process.GetProcessesByName("&lt;Name here&gt;")[0].Id; var desktop = AutomationElement.RootElement; var bw = AutomationElement.RootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ProcessIdProperty, id)); var datagrid = bw.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.AutomationIdProperty, "lv")); var loginLines = datagrid.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.DataItem)); foreach (AutomationElement loginLine in loginLines) { var loginInstance = new Login { IP = new IP() }; var loginLinesDetails = loginLine.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Custom)); for (var i = 0; i &lt; loginLinesDetails.Count; i++) { var cacheRequest = new CacheRequest { AutomationElementMode = AutomationElementMode.None, TreeFilter = Automation.RawViewCondition }; cacheRequest.Add(AutomationElement.NameProperty); cacheRequest.Add(AutomationElement.AutomationIdProperty); cacheRequest.Push(); var targetText = loginLinesDetails[i].FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty, "TextBlock")); cacheRequest.Pop(); var myString = targetText.Cached.Name; #region Determine data and write to return object //Removed private information #endregion } } returnLogins.Add(loginInstance); } return returnLogins; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload