Note: groups.io will be down for maintenance this evening, starting at 2AM Pacific Time (9AM Friday 10/17/2019 UTC), for up to two hours.
Subscribing to UIAutomation events
It's me with the UIA DataGrid again...
Now they've added events to the UIA DataGrid and I'm able to subscribe to it from C# as follows:
UIAeventHandler = new AutomationEventHandler(OnUIAutomationEvent)
And then unsubscribe like this:
if (UIAeventHandler != null)
} // if
The method that's getting called when the event is raised looks like this:
private static void OnUIAutomationEvent(object src, AutomationEventArgs e)
// Make sure the element still exists. Elements such as tooltips
// can disappear before the event is processed.
sourceElement = src as AutomationElement;
if (e.EventId == SelectionPattern.InvalidatedEvent)
Console.WriteLine("--- Markering ---");
var s = grid.GetCurrentPattern(SelectionPattern.Pattern) as SelectionPattern;
foreach (var c in s.Current.GetSelection())
var v = c.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
} // foreach
catch (Exception ex)
Console.WriteLine("Fel när markerad rad hämtades");
} // if
I have the following questions:
1. How do I subscribe to an UIA event in an app m module? I will create a class for the specific UIA element type.
2. How do I get hold of the Selection pattern and the Value patterns for an UIA element? When trying to get hold of the UIASelectionPattern NVDA says that it isn't implemented. The UIASelectionItemPattern is shown when I do a dir(nav) in the Python console but that pattern isn't implemented by the DataGrid.
It seems so close because I can hook up the grid event and print the selection to the console in C# but not in Python. Can anyone point me in the right direction?
0701- 75 98 56