diff --git a/docs/core/compatibility/6.0.md b/docs/core/compatibility/6.0.md index 550563498f11d..71a53b1ec2dd7 100644 --- a/docs/core/compatibility/6.0.md +++ b/docs/core/compatibility/6.0.md @@ -116,6 +116,7 @@ If you're migrating an app to .NET 6, the breaking changes listed here might aff | - | - | | [Selected TableLayoutSettings properties throw InvalidEnumArgumentException](windows-forms/6.0/tablelayoutsettings-apis-throw-invalidenumargumentexception.md) | Preview 1 | | [DataGridView-related APIs now throw InvalidOperationException](windows-forms/6.0/null-owner-causes-invalidoperationexception.md) | Preview 4 | +| [ListViewGroupCollection methods throw new InvalidOperationException](windows-forms/6.0/listview-invalidoperationexception.md) | RC 2 | | [NotifyIcon.Text maximum text length increased](windows-forms/6.0/notifyicon-text-max-text-length-increased.md) | Preview 1 | | [Some APIs throw ArgumentNullException](windows-forms/6.0/apis-throw-argumentnullexception.md) | Preview 1-4 | | [TreeNodeCollection.Item throws exception if node is assigned elsewhere](windows-forms/6.0/treenodecollection-item-throws-argumentexception.md) | Preview 1 | diff --git a/docs/core/compatibility/toc.yml b/docs/core/compatibility/toc.yml index c76f8c6194e4d..c8b1017bc1ec1 100644 --- a/docs/core/compatibility/toc.yml +++ b/docs/core/compatibility/toc.yml @@ -153,6 +153,8 @@ items: href: windows-forms/6.0/apis-throw-argumentnullexception.md - name: DataGridView APIs throw InvalidOperationException href: windows-forms/6.0/null-owner-causes-invalidoperationexception.md + - name: ListViewGroupCollection methods throw new InvalidOperationException + href: windows-forms/6.0/listview-invalidoperationexception.md - name: NotifyIcon.Text maximum text length increased href: windows-forms/6.0/notifyicon-text-max-text-length-increased.md - name: TableLayoutSettings properties throw InvalidEnumArgumentException @@ -843,6 +845,8 @@ items: href: windows-forms/6.0/apis-throw-argumentnullexception.md - name: DataGridView APIs throw InvalidOperationException href: windows-forms/6.0/null-owner-causes-invalidoperationexception.md + - name: ListViewGroupCollection methods throw new InvalidOperationException + href: windows-forms/6.0/listview-invalidoperationexception.md - name: NotifyIcon.Text maximum text length increased href: windows-forms/6.0/notifyicon-text-max-text-length-increased.md - name: TableLayoutSettings properties throw InvalidEnumArgumentException diff --git a/docs/core/compatibility/windows-forms/6.0/listview-invalidoperationexception.md b/docs/core/compatibility/windows-forms/6.0/listview-invalidoperationexception.md new file mode 100644 index 0000000000000..af449dd681959 --- /dev/null +++ b/docs/core/compatibility/windows-forms/6.0/listview-invalidoperationexception.md @@ -0,0 +1,51 @@ +--- +title: "Breaking change: ListViewGroupCollection methods throw new InvalidOperationException" +description: Learn about the breaking change in .NET 6 where some ListViewGroupCollection methods throw a new InvalidOperationException if the ListView is in virtual mode. +ms.date: 09/23/2021 +--- +# ListViewGroupCollection methods throw new InvalidOperationException + +Previously, an was thrown if methods were invoked on a in virtual mode *and* the had already been created. Starting in .NET 6, these methods now only check if the is in virtual mode. If it is, they throw an with a more descriptive message. + +## Previous behavior + +Consider the following code that adds a to a : + +```csharp +ListViewGroup group1 = new ListViewGroup +{ + Header = "CollapsibleGroup1", + CollapsedState = ListViewGroupCollapsedState.Expanded +}; + +listView.Groups.Add(group1); +``` + +This code produced an with the following message: + +**When the ListView is in virtual mode, you cannot enumerate through the ListView items collection using an enumerator or call GetEnumerator. Use the ListView items indexer instead and access an item by index value.** + +## New behavior + +The same code from the [Previous behavior](#previous-behavior) section produces an with the following message: + +**You cannot add groups to the ListView groups collection when the ListView is in virtual mode.** + +## Reason for change + +The new message is more understandable. In addition, it closes a workaround where the developer could add a to the before the was created. + +## Version introduced + +.NET 6.0 RC 2 + +## Recommended action + +- Review and, if necessary, update your code so that it doesn't add a to a in virtual mode. +- If your code handles exceptions, you may need to update the message to reflect that the is in virtual mode. + +## Affected APIs + +- +- +-