C# Bugs ListView
Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio
The Problem
A ListView control may not show it's Vertical ScrollBar when it's needed, even if the ListView.Scrollable property is set to true. The source of this problem comes from toggling the ListView.CheckBoxes property, and only occurs under a specific condition. The bug is in the fact that changing the ListView.CheckBoxes property to true does not re-check the minimum height needed for a Vertical ScrollBar.
To Reproduce:
- The
ListView.CheckBoxesproperty must be false. - Add just enough additional
ListViewItemsto theListViewso the height of all the items without CheckBoxes fits into theListView, but the height of all the items with CheckBoxes does not fit into the control. - Set the
ListView.CheckBoxesproperty to true. This will not cause .NET to add a ScrollBar if the height change forces some items out of view.
The ListView will not have a Vertical ScrollBar until you perform some action on it, such as resizing it or manually scrolling to the last item in the list (either of these actions will trigger .NET to add a scrollbar).
This bug was found in Microsoft .NET Framework v2.0.50727 using C#.
The Solution
Until this bug is fixed, the best solution is to set the ListView.CheckBoxes property to true before adding items to the ListView. Once the items are added, then make the decision to enable/disable the Checkboxes.