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
{{ message }}
Repository navigation
ComboBox.SelectedIndexChanged not firing if SelectedIndex is set before OnHandleCreated #1311
🪲 bugProduct bug (most likely)💥 regression-previewRegression from a preview releasetenet-compatibilityIncompatibility with previous versions or with WinForms for .NET Framework
Setting ComboBox.SelectedIndex in a form's constructor disables further firing of the SelectedIndexChanged event, in .NET Core. It seems it has to do with the availability of the window and control handles. It works OK in the full framework, but it fails in .NET Core. Looks like a breaking change.
(where's the bug template?)
Steps for reproduction:
Create a new WinForms app in .NET Core.
Add a combo box and fill its Items with three lines (let's say: One, Two, Three).
Add a label control.
Handle the SelectedIndexChanged from the combo to something like label1.Text = comboBox1.Text;
Execute it. It will run fine when selecting items in the combo box.
Now add an assignment to comboBox1.SelectedIndex in the form's constructor. It doesn't matter the value. Let's say it's 0.
Run it again: the combo will stop firing to the SelectedIndexChanged event.
Override OnHandleCreated from the form, and move comboBox1.SelectedIndex = 0 to the new method (leaving the constructor in its initial state). Execute. The combo will run fine.
@Olina-Zhang can you try repro it and if it repros, can you please attach a sample repro app here? Can you also check if this is a regression from .NET framework?
WindowsFormsAppCore.zip
Repro added. The repro has two forms: you don't need the second one. It's just that I first isolated the bug using a secondary form. However, you just need a single combobox in the main form to reproduce it.
@dreddy-work we can repro this issue in Core latest build, and cannot repro in .Net 4.8 latest build. It seems a regression issue in Core. Here is the sample app with same code for .Net Core and .Net framework 4.8
ListView (#1607) and RichTextBox (#1644) also have problems firing events in .NET Core when calling certain methods in the Form constructor. Starts looking like a general problem.
Unfortunately the best I can tell so far is that this came from #1034. 😭 I walked back the branches of the commit tree to this change. I'm easily confused by git, so if someone can check me that would be greatly appreciated. f38a7a1 repros the issue. 38a0d1b does not.
I'll give the change a closer look tomorrow to see if I can find the culprit.
I found the issue. Ordering got flipped with switching as to is. I presume the tooling was at fault here. We should audit that part of #1034 thoroughly to make sure nothing else got reordered.
This has to be one of the longest investigations I've done for such a small fix. :) Debugging the message loops is extremely painful- I've got a number of changes for V5 that will simplify the process somewhat.
Reacted by Tobias Käs and Zachary Danz
Reacted by Tobias Käs, Matthew Beardmore and Zachary Danz
Reacted by Zachary Danz
Reacted by Igor Velikorossov and Matthew Beardmore
🪲 bugProduct bug (most likely)💥 regression-previewRegression from a preview releasetenet-compatibilityIncompatibility with previous versions or with WinForms for .NET Framework
Activity
RussKie commentedon Jul 10, 2019
Please fill the bug template provided and supply steps to reproduce/demo app.
Thank you
IanMarteens commentedon Jul 10, 2019
(where's the bug template?)
Steps for reproduction:
IanMarteens commentedon Jul 10, 2019
About the environment: Windows 10 v1093, Visual Studio 2019 16.1.6 with previews allowed, and .NET Core Preview 6.
dreddy-work commentedon Jul 10, 2019
@Olina-Zhang can you try repro it and if it repros, can you please attach a sample repro app here? Can you also check if this is a regression from .NET framework?
IanMarteens commentedon Jul 11, 2019
WindowsFormsAppCore.zip
Repro added. The repro has two forms: you don't need the second one. It's just that I first isolated the bug using a secondary form. However, you just need a single combobox in the main form to reproduce it.
Olina-Zhang commentedon Jul 11, 2019
@dreddy-work we can repro this issue in Core latest build, and cannot repro in .Net 4.8 latest build. It seems a regression issue in Core. Here is the sample app with same code for .Net Core and .Net framework 4.8
.Net Core:
WindowsFormsApp9.zip
.Net framework:
WindowsFormsApp8.zip
After run them:

IanMarteens commentedon Jul 26, 2019
Move any initializations involving controls from the constructor into an overridden OnHandleCreated method.
9 remaining items
weltkante commentedon Aug 16, 2019
ListView (#1607) and RichTextBox (#1644) also have problems firing events in .NET Core when calling certain methods in the Form constructor. Starts looking like a general problem.
JeremyKuhne commentedon Aug 18, 2019
Unfortunately the best I can tell so far is that this came from #1034. 😭 I walked back the branches of the commit tree to this change. I'm easily confused by git, so if someone can check me that would be greatly appreciated. f38a7a1 repros the issue. 38a0d1b does not.
I'll give the change a closer look tomorrow to see if I can find the culprit.
cc: @zsd4yr
JeremyKuhne commentedon Aug 18, 2019
I found the issue. Ordering got flipped with switching
astois. I presume the tooling was at fault here. We should audit that part of #1034 thoroughly to make sure nothing else got reordered.This has to be one of the longest investigations I've done for such a small fix. :) Debugging the message loops is extremely painful- I've got a number of changes for V5 that will simplify the process somewhat.
Zheng-Li01 commentedon Aug 27, 2019
Verified with latest .NET Core 3.0 Preview 9 3.0.100.14004 build, it’s not reproduced for now.
RussKie commentedon Aug 27, 2019
Thank you!