Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,24 @@ private bool LookupValue(object? formattedValue, out object? value)
object? item;
if (DisplayMemberProperty is not null || ValueMemberProperty is not null)
{
// When the cell is in edit mode, check the item the user actually selected first.
// A linear search through the data source would return the first item whose display
// property matches, which is wrong when multiple items share the same display text.
if (OwnsEditingComboBox(RowIndex))
{
object? selectedItem = EditingComboBox.SelectedItem;
if (selectedItem is not null)
{
PropertyDescriptor displayProp = DisplayMemberProperty ?? ValueMemberProperty!;
object? selectedDisplayValue = displayProp.GetValue(selectedItem);
if (selectedDisplayValue is not null && selectedDisplayValue.Equals(formattedValue))
{
value = GetItemValue(selectedItem);
return true;
}
}
}

// Now look up the item in the DataGridViewComboBoxCell datasource - this can be horribly inefficient
// and it uses reflection which makes it expensive - ripe for optimization
item = ItemFromComboBoxDataSource((DisplayMemberProperty ?? ValueMemberProperty)!, formattedValue);
Expand Down
Loading