Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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 @@ -25593,6 +25593,23 @@ private void ReleaseMouse()
Capture = false;
}

private static void ReleaseRowUiaProviders(DataGridViewRow row)
{
if (!row.IsAccessibilityObjectCreated)
{
return;
}

DataGridViewCellCollection cells = row.Cells;
for (int cellIndex = 0; cellIndex < cells.Count; cellIndex++)
{
cells[cellIndex].ReleaseUiaProvider();
}

row.HeaderCell.ReleaseUiaProvider();
row.ReleaseUiaProvider();
}

internal override void ReleaseUiaProvider(HWND handle)
{
if (!IsAccessibilityObjectCreated)
Expand All @@ -25602,17 +25619,22 @@ internal override void ReleaseUiaProvider(HWND handle)

if (OsVersion.IsWindows8OrGreater())
{
foreach (DataGridViewRow row in Rows)
// Collect unique rows from SharedList using HashSet for deduplication.
// SharedList may have over several hundred thousand entries, but most point to the same shared row instances.
HashSet<DataGridViewRow> uniqueRows = [];
List<DataGridViewRow> sharedList = Rows.SharedList;
for (int i = 0; i < sharedList.Count; i++)
{
foreach (DataGridViewCell cell in row.Cells)
{
cell.ReleaseUiaProvider();
}
uniqueRows.Add(sharedList[i]);
}

row.HeaderCell.ReleaseUiaProvider();
row.ReleaseUiaProvider();
// Release UIA providers for unique rows
foreach (DataGridViewRow row in uniqueRows)
{
ReleaseRowUiaProviders(row);
}

// Release column header accessibility objects
foreach (DataGridViewColumn column in Columns)
{
column.HeaderCell.ReleaseUiaProvider();
Expand All @@ -25621,7 +25643,6 @@ internal override void ReleaseUiaProvider(HWND handle)
_editingPanel?.ReleaseUiaProvider(HWND.Null);
_editingPanelAccessibleObject = null;
_topLeftHeaderCell?.ReleaseUiaProvider();

if (AccessibilityObject is DataGridViewAccessibleObject accessibleObject)
{
accessibleObject.ReleaseChildUiaProviders();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1064,9 +1064,21 @@ internal void RemoveAtInternal(int index, bool force)

if (DataGridView.IsAccessibilityObjectCreated && OsVersion.IsWindows8OrGreater())
{
foreach (DataGridViewRow row in DataGridView.Rows)
// Collect unique rows from SharedList using HashSet for deduplication.
HashSet<DataGridViewRow> uniqueRows = [];
List<DataGridViewRow> sharedList = DataGridView.Rows.SharedList;
for (int i = 0; i < sharedList.Count; i++)
{
row.Cells[index].ReleaseUiaProvider();
uniqueRows.Add(sharedList[i]);
}

// Release UIA providers for the cell at the removed column index
foreach (DataGridViewRow row in uniqueRows)
{
if (row.IsAccessibilityObjectCreated)
{
row.Cells[index].ReleaseUiaProvider();
}
}

dataGridViewColumn.HeaderCell.ReleaseUiaProvider();
Expand Down
Loading