Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ public partial class ListView : Control
// We cache the NewWidth supplied by the user and use it on HDN_ENDTRACK to set the final column width.
private int _newWidthForColumnWidthChangingCancelled = -1;

// Tracks indices of ListViewItems that have been accessed by UIA in virtual mode,
// so their UIA providers can be properly released later without triggering item retrieval.
private readonly HashSet<int> _uiaAccessedIndices = [];
/// <summary>
/// Creates an empty ListView with default styles.
/// </summary>
Expand Down Expand Up @@ -5084,16 +5087,36 @@ public void RedrawItems(int startIndex, int endIndex, bool invalidateOnly)
}
}

internal void NotifyUiaCreated(int index)
{
if (VirtualMode)
{
_uiaAccessedIndices.Add(index);
}
}

internal override void ReleaseUiaProvider(HWND handle)
{
if (!OsVersion.IsWindows8OrGreater())
{
return;
}

for (int i = 0; i < Items.Count; i++)
if (VirtualMode)
{
foreach (int index in _uiaAccessedIndices)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In virtual mode, ListViewItem objects aren't real objects; instead, they're dynamically generated using the RetrieveVirtualItem method.

If the data source changes (such as insertions, deletions, or sorting), the original index may no longer correspond to the original item.

{
Items.GetItemByIndex(index)?.ReleaseUiaProvider();
}

_uiaAccessedIndices.Clear();
}
else
{
Items.GetItemByIndex(i)?.ReleaseUiaProvider();
for (int i = 0; i < Items.Count; i++)
{
Items.GetItemByIndex(i)?.ReleaseUiaProvider();
}
}

if (_defaultGroup is not null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ internal virtual AccessibleObject AccessibilityObject
};
}

owningListView.NotifyUiaCreated(Index);

return _accessibilityObject;
}
}
Expand Down
Loading