You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Did it work in any of the earlier releases of .NET Core or .NET 5+?
No response
Issue description
In DataGridViewComboBoxCell, the methods InitializeDisplayMemberPropertyDescriptor and InitializeValueMemberPropertyDescriptor throw ArgumentExceptions with the message SR.DataGridViewComboBoxCell_FieldNotFound.
I have not been able to find the source string for the message, but it is "Field called {0} does not exist.", with the appropriate substitution for "{0}".
It is my understanding that binding happens to properties, not fields, and thus the error message should say "Property called {0} does not exist.". The current error message is especially confusing to newcomers to data binding who try to bind to fields since it claims exactly the opposite of what's true (e.g. you try to bind to a field called Item1, and you get an error saying "Field called Item1 does not exist.").
Steps to reproduce
Create a new Windows Forms project and use the following code.
publicpartialclassForm1:Form{publicForm1(){InitializeComponent();DataGridViewComboBoxColumncolumn=new();DataGridViewdataGridView=new();FlowLayoutPanelflowLayoutPanel=new();Controls.Add(flowLayoutPanel);flowLayoutPanel.Controls.Add(dataGridView);dataGridView.Columns.Add(column);column.DataSource=newValueTuple<string,int>[]{new("One",1)};// The following line throws System.ArgumentException: 'Field called Item1 does not exist.'column.DisplayMember=nameof(ValueTuple<string,int>.Item1);column.ValueMember=nameof(ValueTuple<string,int>.Item2);}}
The text was updated successfully, but these errors were encountered:
…gested, ensuring it reflects the correct value.
Fixesdotnet#12810
- The original resource file used the term "field" instead of "property," which caused confusion in the context where we were searching for a property with a given name.
- Updated the resource string to replace "field" with "property" as suggested, ensuring it reflects the correct value.
- None
- No
- Minimal
- Manual
- `10.0.100-alpha.1.25064.3`
Verified in the latest .NET 10 SDK build: 10.0.100-preview.2.25105.6, it was fixed: now the error message for displayMenber and valueMember of dataGridViewComboBoxColumn uses property string:
.NET version
9.0.102
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
In
DataGridViewComboBoxCell
, the methodsInitializeDisplayMemberPropertyDescriptor
andInitializeValueMemberPropertyDescriptor
throwArgumentException
s with the messageSR.DataGridViewComboBoxCell_FieldNotFound
.winforms/src/System.Windows.Forms/src/System/Windows/Forms/Controls/DataGridView/DataGridViewComboBoxCell.cs
Lines 1360 to 1362 in e2942ed
winforms/src/System.Windows.Forms/src/System/Windows/Forms/Controls/DataGridView/DataGridViewComboBoxCell.cs
Lines 1391 to 1393 in e2942ed
I have not been able to find the source string for the message, but it is "Field called {0} does not exist.", with the appropriate substitution for "{0}".
It is my understanding that binding happens to properties, not fields, and thus the error message should say "Property called {0} does not exist.". The current error message is especially confusing to newcomers to data binding who try to bind to fields since it claims exactly the opposite of what's true (e.g. you try to bind to a field called
Item1
, and you get an error saying "Field called Item1 does not exist.").Steps to reproduce
Create a new Windows Forms project and use the following code.
The text was updated successfully, but these errors were encountered: