Skip to content

WI01073344 - .NET 10 fixing - Group 12A - DataGrid selection state fix#18

Open
Rick-Xu-WTG wants to merge 1 commit into
masterfrom
RX/WI01073344-Net10-fixing-Group12A
Open

WI01073344 - .NET 10 fixing - Group 12A - DataGrid selection state fix#18
Rick-Xu-WTG wants to merge 1 commit into
masterfrom
RX/WI01073344-Net10-fixing-Group12A

Conversation

@Rick-Xu-WTG
Copy link
Copy Markdown

Summary

Fix DataGrid row selection state loss during row recreation in .NET 10.

Problem

When upgrading from .NET 8 to .NET 10, DataGrid's internal row recreation cycle destroys row objects, causing all selection state to be lost. This breaks 10+ tests in CargoWise1 PR #50917 (Group 12A).

Root Cause

.NET 10 triggers SetDataGridRows() which calls ResetUIState() → clears row-level selection → rows get recreated as new objects. The old selection state is destroyed with the old row objects.

Fix

Added HashSet<int> _selectedRowCache field that maintains selection state independently of DataGrid's internal row arrays:

  • Select(row): stores row index in cache
  • IsSelected(row): falls back to cache when row array is empty/mismatched
  • UnSelect(row): removes from cache
  • ResetSelection(): intentionally does NOT clear cache (survives row recreation)
  • SetDataGridRows(): re-applies cached selections to new row objects after recreation

Testing

  • 10/10 net10.0 framework tests pass ✅
  • 9/10 Winzor framework tests pass ✅ (1 failure is unrelated MenuItem lifecycle issue)

Changed File

  • src/System.Windows.Forms/System/Windows/Forms/Controls/Unsupported/DataGrid/DataGrid.cs

…uring row recreation (.NET 10 fix)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant