-
Notifications
You must be signed in to change notification settings - Fork 1k
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
BindingSource.Sort fails with custom IBindingListView in .NET 9 (worked in .NET 8) #13061
Comments
The bug was caused by this change: https://github.com/dotnet/winforms/pull/10172/files#diff-be7f960595c89e574536157bf61838085bce49d7e8c48a7f96a58e6764b6a533L994-R997 In the older code The current code on the winforms/src/System.Windows.Forms/src/System/Windows/Forms/DataBinding/BindingSource.cs Lines 981 to 992 in 61a4f2a
Because the buggy source code of BindingSource is in the dotnet/winforms repository, I think this issue should be moved there.
I think you can work around the bug by writing |
@merriemcgaw I do not seem to have permission to transfer issues to winforms, but this looks like an issue for winforms to consider |
Should I re-create this in winforms? |
it is transferrable, I just lack the permission in winforms ;) |
Moved. |
Get the below results. |
Description
BindingSource.Sort fails with custom IBindingListView in .NET 9 (worked in .NET 8)
Reproduction Steps
Create a custom class implementing IBindingListView and IBindingList, inheriting from BindingList (see code in Other Information).
Set it as the DataSource of a BindingSource.
Set BindingSource.Sort = "Property desc" where Property exists in the item type.
Observe the result.
Expected behavior
In .NET 8, BindingSource.Sort calls IBindingList.ApplySort, sorting the list.
The list is sorted, and no exception is thrown.
Actual behavior
In .NET 9, it throws "Sort string contains a property that is not in the IBindingList" without calling IBindingList.ApplySort.
Regression?
It worked in .net8
Known Workarounds
In my actual application, I can sort the BindingListView before I pass it to the BindingSource and it works. Once the BindingSource is bound to the DataGridView, you can sort by clicking the column headers. I tried sorting the BindingSource after it was passed to the DataGridView and the Sort property still threw the above error. The problem seems to be with setting the Sort property of the BindingSource.
Configuration
.NET 9.0
Windows 11
x64
Other information
namespace WinFormsApp1
{
using System.ComponentModel;
using System.Windows.Forms;
}
The text was updated successfully, but these errors were encountered: