ComboBox.Text can't select items in some cases
See original GitHub issue- .NET Core Version: All. Also
- Windows version: 7 and 10
- Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes
Problem description:
When ComboBox.IsEditable = False
, setting the ComboBox.Text
to a text that matches an item in the ComboBox should select this item. This doesn’t happen in some cases, like setting the Text property to “Test” while the ComboBox contains the items "test", "Test", "abc"
or "test1", "Test", "abc"
or "Test1", "Test", "abc"
.
It seems that matching Test
to test
, test1
, “Test1” causes some error that apports the search (which doesn’t happen in WinForms by the way). That proves this submission, is that changing the order (ComboBox contains the items "Test", "test", "abc"
) will make the combobox select the item Test correctly!
Minimal repro:
<StackPanel>
<ComboBox x:Name="ComboBox1" IsEditable="False">
<ComboBoxItem>test</ComboBoxItem>
<ComboBoxItem>Test</ComboBoxItem>
<ComboBoxItem>abc</ComboBoxItem>
</ComboBox>
<Button Click="Button_Click">Test</Button>
</StackPanel>
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
ComboBox1.Text = "Test"
End Sub
Run the app and click the button. Nothing will be selected in the comboBox.
Expected behavior is to select the Test
item.
Issue Analytics
- State:
- Created 10 months ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
No. Winforms and WPF are fundamentally different frameworks and there should be no such expectations.
The documentation (https://learn.microsoft.com/en-us/dotnet/api/system.windows.controls.combobox.text) says otherwise:
Sounds like the current behavior is by design… To select an item, find the item you want and use the
SelectedItem
property.This submission has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 14 days.
It will be closed if no further activity occurs within 7 days of this comment.