You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Stale selected-item count cache causes IndexOutOfRangeException in ListBox.RefreshItems #15360
Did it work in any of the earlier releases of .NET Core or .NET 5+?
Not tested/verified
Issue description
The customer's application encounters System.IndexOutOfRangeException while loading a form that contains a CheckedListBox. After the list's items, selection, and checked states have been set, enabling the horizontal scrollbar in the form's Load handler triggers the exception and interrupts the affected control's initialization. The customer reports that the issue occurs with some item counts and checked states but not others.
Screen.Recording.2026-11-04.140939.mp4
Steps to reproduce
Open the desired project in Visual Studio, build it, and start debugging.
During initialization in the constructor, before the control's native handle is created, it adds "A", sets SelectedIndex=0, and reads SelectedItems.Count.
It adds "B" and then sets HorizontalScrollbar=true.
Observe System.IndexOutOfRangeException at the HorizontalScrollbar assignment in the form's constructor, before the form is displayed.
The reproduction code in the form's constructor is:
public ReproForm()
{
CheckedListBox list = new CheckedListBox { Dock = DockStyle.Fill };
Controls.Add(list);
list.Items.Add("A");
list.SelectedIndex = 0;
_ = list.SelectedItems.Count;
list.Items.Add("B");
list.HorizontalScrollbar = true;
}
Activity
Zheng-Li01 commentedon Nov 12, 2026
Verified the issue with .NET 12 12.0.100-alpha.1.26560.109 build, the issue has been fixed as below screenshot.