-
Notifications
You must be signed in to change notification settings - Fork 6k
Add ListView breaking change #26249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ListView breaking change #26249
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <xref:System.InvalidOperationException> was thrown if <xref:System.Windows.Forms.ListViewGroupCollection> methods were invoked on a <xref:System.Windows.Forms.ListViewItem.ListView> in virtual mode *and* the <xref:System.Windows.Forms.Control.Handle> had already been created. Starting in .NET 6, these <xref:System.Windows.Forms.ListViewGroupCollection> methods now only check if the <xref:System.Windows.Forms.ListViewItem.ListView> is in virtual mode. If it is, they throw an <xref:System.InvalidOperationException> with a more descriptive message. | ||
|
||
## Previous behavior | ||
|
||
Consider the following code that adds a <xref:System.Windows.Forms.ListViewGroup> to a <xref:System.Windows.Forms.ListViewItem.ListView>: | ||
|
||
```csharp | ||
ListViewGroup group1 = new ListViewGroup | ||
{ | ||
Header = "CollapsibleGroup1", | ||
CollapsedState = ListViewGroupCollapsedState.Expanded | ||
}; | ||
|
||
listView.Groups.Add(group1); | ||
``` | ||
|
||
This code produced an <xref:System.InvalidOperationException> 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 <xref:System.InvalidOperationException> with the following message: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The previous/new behavior sections don't show anything about the handle being created or not. Is there a way to show that in the code? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @SergeySmirnov-Akvelon to confirm on that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Initially, the issue was reproduced only when the Now, since the virtual mode is always checked, we also display an error only about the virtual mode, without any data about the |
||
|
||
**You cannot add groups to the ListView groups collection when the ListView is in virtual mode.** | ||
|
||
## Reason for change | ||
|
||
The new <xref:System.InvalidOperationException> message is more understandable. In addition, it closes a workaround where the developer could add a <xref:System.Windows.Forms.ListViewGroup> to the <xref:System.Windows.Forms.ListViewItem.ListView> before the <xref:System.Windows.Forms.Control.Handle> 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 <xref:System.Windows.Forms.ListViewGroup> to a <xref:System.Windows.Forms.ListViewItem.ListView> in virtual mode. | ||
- If your code handles <xref:System.InvalidOperationException> exceptions, you may need to update the message to reflect that the <xref:System.Windows.Forms.ListViewItem.ListView> is in virtual mode. | ||
gewarren marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Affected APIs | ||
|
||
- <xref:System.Windows.Forms.ListViewGroupCollection.Add%2A?displayProperty=fullName> | ||
- <xref:System.Windows.Forms.ListViewGroupCollection.AddRange%2A?displayProperty=fullName> | ||
- <xref:System.Windows.Forms.ListViewGroupCollection.Insert(System.Int32,System.Windows.Forms.ListViewGroup)?displayProperty=fullName> |
Uh oh!
There was an error while loading. Please reload this page.