dotnet/winforms
在 GitHub 查看ComboBox internal state not consistent when inserting at SelectedIndex and IsHandleCreated == false
Open
#6,689 创建于 2022年2月13日
:books: documentationhelp wanted
仓库指标
- Star
- (4,100 star)
- PR 合并指标
- (平均合并 14天 22小时) (30 天内合并 56 个 PR)
描述
- .NET Core Version: 6.0.101
- Have you experienced this same bug with .NET Framework?: Yes
Problem description:
Add items to the ComboBox and select one:
comboBox1.Items.Add("Item 1");
comboBox1.Items.Add("Item 2");
comboBox1.Items.Add("Item 3");
comboBox1.SelectedIndex = 1;
Now insert at the selected index: comboBox1.Items.Insert(1, "Test");
If the handle has been created:
- Item will be inserted into collection
SelectedIndexwill incrementSelectedItemandTextremain consistent
If the handle has not been created:
- Item will be inserted into collection
SelectedIndexwill remain the sameSelectedItemwill be the newly inserted itemTextwill match the oldSelectedItem
Issue discovered while adding events to Items collection (#6673)
Expected behavior:
- Internal state of control should remain consistent
- Behavior when handle has not yet been created should match that of when it has been
Minimal repro:
- Create new WinForms project
- Add the following to
Mainjust afterApplicationConfiguration.Initialize();
var comboBox = new ComboBox();
comboBox.Items.Add("Item 1");
comboBox.Items.Add("Item 2");
comboBox.Items.Add("Item 3");
comboBox.SelectedIndex = 1;
comboBox.Items.Insert(1, "Test");
- Set a breakpoint on
comboBox.Items.Insert(1, "Test"); - Observe the values of
SelectedIndex,SelectedItemandTextbefore and after that line executes