In the image below there is an area that has an unknown (user) class. This is not a grid or table.

I need to be able to:
- select rows in this area
- to get the value from each cell
The problem is that this is not a general type of element - I have no idea how to solve this problem or solve it myself. So far, the code is as follows:
Process[] proc = Process.GetProcessesByName("programname"); AutomationElement window = AutomationElement.FromHandle(proc [0].MainWindowHandle); PropertyCondition xEllist2 = new PropertyCondition(AutomationElement.ClassNameProperty, "CustomListClass", PropertyConditionFlags.IgnoreCase); AutomationElement targetElement = window.FindFirst(TreeScope.Children, xEllist2);
I already tried to threaten this Region as a text field, as a grid, as a drop-down list, but so far I have not been able to solve my problem. Does anyone have any tips on how to capture data from this area and iterate over rows?
EDIT: Sorry, I made the wrong assumption. Actually, the header (column 1, column 2, column 3) and the "lower half" of this area are different types of controls !!
Thanks to Wininspector, I was able to get additional information about these types of controls:
- The header has the following properties: HeaderControl 0x056407DC (90441692) Atom: # 43288 0xFFFFFFFF (-1)
- and in the lower half: ListControl 0x056408A4 (90441892) Atom: # 43288 0x02A6FDA0 (44498336)
The code I showed earlier is just a List item, so this is an update:
Process[] proc = Process.GetProcessesByName("programname"); AutomationElement window = AutomationElement.FromHandle(proc [0].MainWindowHandle); //getting the header PropertyCondition xEllist3 = new PropertyCondition(AutomationElement.ClassNameProperty, "CustomHeaderClass", PropertyConditionFlags.IgnoreCase); AutomationElement headerEl = XElAE.FindFirst(TreeScope.Children, xEllist3); //getting the list PropertyCondition xEllist2 = new PropertyCondition(AutomationElement.ClassNameProperty, "CustomListClass", PropertyConditionFlags.IgnoreCase); AutomationElement targetElement = window.FindFirst(TreeScope.Children, xEllist2);
After further thought, I tried to get all the column names:
AutomationElementCollection headerLines = headerEl.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.HeaderItem)); string headertest = headerLines[0].GetCurrentPropertyValue(AutomationElement.NameProperty) as string; textBox2.AppendText("Header 1: " + headertest + Environment.NewLine);
Unfortunately, in debug mode, the count element in "headerLines" is 0, so the program throws an error.
Edit 2:. The answer to this question is below - I installed Unmanaged UI Automation, which has better features than the default UIA. http://uiacomwrapper.codeplex.com/ How do you use an outdated template to capture data from an unknown control type?
if((bool)datagrid.GetCurrentPropertyValue(AutomationElementIdentifiers.IsLegacyIAccessiblePatternAvailableProperty)) { var pattern = ((LegacyIAccessiblePattern)datagrid.GetCurrentPattern(LegacyIAccessiblePattern.Pattern)); var state = pattern.Current.State; }
Edit 3. IUIAutoamtion approach (not working at the moment)
_automation = new CUIAutomation(); cacheRequest = _automation.CreateCacheRequest(); cacheRequest.AddPattern(UiaConstants.UIA_LegacyIAccessiblePatternId); cacheRequest.AddProperty(UiaConstants.UIA_LegacyIAccessibleNamePropertyId); cacheRequest.TreeFilter = _automation.ContentViewCondition; trueCondition = _automation.CreateTrueCondition(); Process[] ps = Process.GetProcessesByName("program"); IntPtr hwnd = ps[0].MainWindowHandle; IUIAutomationElement elementMailAppWindow = _automation.ElementFromHandle(hwnd); List<IntPtr> ls = new List<IntPtr>(); ls = GetChildWindows(hwnd); foreach (var child in ls) { IUIAutomationElement iuiae = _automation.ElementFromHandle(child); if (iuiae.CurrentClassName == "CustomListClass") { var outerArayOfStuff = iuiae.FindAllBuildCache(interop.UIAutomationCore.TreeScope.TreeScope_Children, trueCondition, cacheRequest.Clone()); var outerArayOfStuff2 = iuiae.FindAll(interop.UIAutomationCore.TreeScope.TreeScope_Children, trueCondition); var countOuter = outerArayOfStuff.Length; var countOuter2 = outerArayOfStuff2.Length; var uiAutomationElement = outerArayOfStuff.GetElement(0);
The code was implemented thanks to this problem:
Reading cell elements from data grid in SysListView32 of another application using C #
As a result:
- countOuter and countOuter2 lengths = 0
- cannot select items (rows from a list)
- impossible to get ANY value
- nothing works.