No exception if DataGridView is null

Previously, a NullReferenceException was thrown in DataGridViewHeaderCell.MouseDownUnsharesRow(DataGridViewCellMouseEventArgs), DataGridViewHeaderCell.MouseEnterUnsharesRow(Int32), DataGridViewHeaderCell.MouseLeaveUnsharesRow(Int32), and DataGridViewHeaderCell.MouseUpUnsharesRow(DataGridViewCellMouseEventArgs) if the DataGridView property was null. That behavior was unexpected and incorrect. These methods have been updated to simply return false if DataGridView is null.

Version introduced

.NET 9 Preview 1

Previous behavior

Previously, the affected methods threw a NullReferenceException when DataGridViewHeaderCell.DataGridView was null.

New behavior

Starting in .NET 9, the affected methods return false if the DataGridViewHeaderCell.DataGridView property is null

Change category

This change is a behavioral change.

Reason for change

The previous behavior was incorrect.

If you were relying on the code to throw a NullReferenceException in this scenario, change your code to check the return value instead.

Affected APIs