Skip to content

Fix ListView destroying StateImageList when toggling CheckBoxes#14652

Open
KSaiSivani wants to merge 1 commit into
dotnet:mainfrom
KSaiSivani:Fix_Issue_3531
Open

Fix ListView destroying StateImageList when toggling CheckBoxes#14652
KSaiSivani wants to merge 1 commit into
dotnet:mainfrom
KSaiSivani:Fix_Issue_3531

Conversation

@KSaiSivani

@KSaiSivani KSaiSivani commented Jun 16, 2026

Copy link
Copy Markdown

Fixes #3531

Proposed changes

  • Update ListView.CheckBoxes setter to call RecreateHandleInternal() when toggling from true → false as well as false → true.

  • Ensure LVM_SETIMAGELIST is resent after handle recreation so the user‑supplied StateImageList is preserved.

  • Prevent native ListView from discarding or corrupting the StateImageList when checkboxes are toggled.

Customer Impact

  • Fixes scenarios where toggling CheckBoxes caused custom state images to disappear or the ImageList to be disposed.

  • Ensures developers can reliably use StateImageList with checkboxes without losing images.

  • Improves stability in apps that dynamically toggle CheckBoxes at runtime.

Regression?

  • No

Risk

  • Low. The change is isolated to the CheckBoxes setter and handle recreation path.

Screenshots

Before

ListView_CheckBoxes_false_without_fix.mp4
ListView_CheckBoxes_true_without_fix.mp4

After

ListView_CheckBoxes_false_with_fix.mp4
ListView_CheckBoxes_true_with_fix.mp4

Test methodology

  • Manually toggled CheckBoxes across multiple views (List, SmallIcon, LargeIcon) with custom state images.

  • Verified items with StateImageIndex retained correct images after toggling.

  • Validated under high DPI scaling to confirm images remained intact.

  • Repeated toggle operations to confirm stability across multiple transitions.

Test environment(s)

  • 11.0.100-preview.3.26170.106
Microsoft Reviewers: Open in CodeFlow

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses win32 ListView behavior that can discard/corrupt a user-supplied StateImageList when ListView.CheckBoxes is toggled at runtime, by ensuring the control handle is recreated when a StateImageList is present.

Changes:

  • Update the CheckBoxes setter to recreate the handle whenever StateImageList is non-null and the handle exists (not only on true → false transitions).
  • Keep the handle-recreation path consistent with existing logic that re-applies state image lists after style changes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +517 to 520
if ((StateImageList is not null && IsHandleCreated) ||
(!value && Alignment == ListViewAlignment.Left && IsHandleCreated) ||
(value && View == View.List && IsHandleCreated) ||
(value && (View == View.SmallIcon || View == View.LargeIcon) && IsHandleCreated))
Comment on lines +517 to 520
if ((StateImageList is not null && IsHandleCreated) ||
(!value && Alignment == ListViewAlignment.Left && IsHandleCreated) ||
(value && View == View.List && IsHandleCreated) ||
(value && (View == View.SmallIcon || View == View.LargeIcon) && IsHandleCreated))
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.

Setting ListView.CheckBoxes after ListView.StateImageList destroys imagelist

2 participants