dotnet / dotnet/wpf

GridPattern.GetItem(RowIndex, ColumnIndex) returns null in UI Automation for ListView with GridView

Open
#9,139 9 comments 0 reactions 0 assignees View on GitHub
Investigate
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

### Description

When using UI Automation to interact with a ListView control where the GridView is set via the ListView.View property, invoking the GridPattern.GetItem(RowIndex, ColumnIndex) method consistently returns null. However, it's observed that when utilizing the DataGrid control, the GetItem method correctly returns cell values. This discrepancy suggests a potential issue specific to ListView controls with GridView setting in UI Automation.

### Reproduction Steps

repro code is https://github.com/matarillo/wpf-gridview-automation

XAML:

```xaml









```

UIA:
```cs
var window = AutomationElement.FromHandle(targetProcess.MainWindowHandle);
var cellValue = GetGridItem(window, "UserGrid", 0, 0);

public static AutomationElement FindControlByAutomationId(AutomationElement aeWindow, string id)
{
Condition condition = new PropertyCondition(AutomationElement.AutomationIdProperty, id, PropertyConditionFlags.IgnoreCase);
TreeWalker treeWalker = new TreeWalker(condition);
return treeWalker.GetFirstChild(aeWindow);
}

public static string GetGridItem(AutomationElement aeWindow, string id, int row, int column)
{
var aeListView = FindControlByAutomationId(aeWindow, id);
var aeGrid = aeListView.GetCurrentPattern(GridPattern.Pattern) as GridPattern;
var item = aeGrid.GetItem(row, column);
return item?.Current.Name;
}
```

### Expected behavior

`GridPattern.GetItem(RowIndex, ColumnIndex)` returns non-null AutomationElement value

### Actual behavior

`GridPattern.GetItem(RowIndex, ColumnIndex)` returns null

### Regression?

This is reproducible when the target framework is set to net6.0-windows or net48-windows.

### Known Workarounds

Use DataGrid

### Impact

_No response_

### Configuration

_No response_

### Other information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.