dotnet / dotnet/winforms

Cell using 'DisplayMember' to find and set value resulting in setting bad value.

Open
#11,311 7 comments 0 reactions 1 assignee Claimed by @KlausLoeffelmann View on GitHub
:beetle: bug area-controls-DataGridView
Dominant language
C#
Stars
4.9k
Forks
1.1k
Avg merge
1d 13m
Merged PRs (30d)
85

Description

### .NET version

```bash
$ dotnet --info
.NET SDK:
Version: 8.0.101
Commit: 6eceda187b
Workload version: 8.0.100-manifests.30fce108
```

### Did it work in .NET Framework?

Not tested/verified

### Did it work in any of the earlier releases of .NET Core or .NET 5+?

_No response_

### Issue description

I created very simple showcase here https://github.com/bukowa/Issue_WinForms_FormattedValue
As you can see if the `DisplayMember` returns the same value it will always be set to the first one.

Basically the value will be set to the first matching occurence of the `DisplayMember` found in the `BindingList`.
![Animation](https://github.com/dotnet/winforms/assets/38087302/7efe6eb2-d445-4b61-b61c-4c84342908cc)

The code is here
https://github.com/dotnet/winforms/blob/1e92b290a6611cdabab4add02b738e9456e5d885/src/System.Windows.Forms/src/System/Windows/Forms/Controls/DataGridView/DataGridViewComboBoxCell.cs#L1508
https://github.com/dotnet/winforms/blob/1e92b290a6611cdabab4add02b738e9456e5d885/src/System.Windows.Forms/src/System/Windows/Forms/Controls/DataGridView/DataGridViewComboBoxCell.cs#L1674

### Steps to reproduce

https://github.com/bukowa/Issue_WinForms_FormattedValue

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.