Skip to content

ComboBox.SelectedIndexChanged not firing if SelectedIndex is set before OnHandleCreated #1311

Closed

Description

@IanMarteens

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.

Activity

  1. RussKie commented on Jul 10, 2019

    @RussKie
    Contributor

    Please fill the bug template provided and supply steps to reproduce/demo app.
    Thank you

  2. IanMarteens commented on Jul 10, 2019

    @IanMarteens
    Author

    (where's the bug template?)
    Steps for reproduction:

    1. Create a new WinForms app in .NET Core.
    2. Add a combo box and fill its Items with three lines (let's say: One, Two, Three).
    3. Add a label control.
    4. Handle the SelectedIndexChanged from the combo to something like label1.Text = comboBox1.Text;
    5. Execute it. It will run fine when selecting items in the combo box.
    6. Now add an assignment to comboBox1.SelectedIndex in the form's constructor. It doesn't matter the value. Let's say it's 0.
    7. Run it again: the combo will stop firing to the SelectedIndexChanged event.
    8. 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.
  3. IanMarteens commented on Jul 10, 2019

    @IanMarteens
    Author

    About the environment: Windows 10 v1093, Visual Studio 2019 16.1.6 with previews allowed, and .NET Core Preview 6.

  4. dreddy-work commented on Jul 10, 2019

    @dreddy-work
    Member

    @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?

  5. added
    🪲 bug
    and removed on Jul 10, 2019
  6. added this to the Future milestone on Jul 10, 2019
  7. IanMarteens commented on Jul 11, 2019

    @IanMarteens
    Author

    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.

  8. Olina-Zhang commented on Jul 11, 2019

    @Olina-Zhang
    Member

    @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

    After run them:
    image

  9. IanMarteens commented on Jul 26, 2019

    @IanMarteens
    Author

    Are there any hints or workarounds for this? That just prevents me from going beyond preview5.

    Move any initializations involving controls from the constructor into an overridden OnHandleCreated method.

  10. added
    💥 regression-preview
    tenet-compatibility
    on Jul 26, 2019
  11. 9 remaining items

  12. weltkante commented on Aug 16, 2019

    @weltkante
    Contributor

    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.

  13. JeremyKuhne commented on Aug 18, 2019

    @JeremyKuhne
    Member

    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

  14. ghost added
    🚧 work in progress
    on Aug 18, 2019
  15. JeremyKuhne commented on Aug 18, 2019

    @JeremyKuhne
    Member

    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.

  16. ghost removed
    🚧 work in progress
    on Aug 20, 2019
  17. Zheng-Li01 commented on Aug 27, 2019

    @Zheng-Li01
    Member

    Verified with latest .NET Core 3.0 Preview 9 3.0.100.14004 build, it’s not reproduced for now.

  18. RussKie commented on Aug 27, 2019

    @RussKie
    Contributor

    Thank you!

  19. ghost locked as resolved and limited conversation to collaborators on Feb 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

🪲 bug💥 regression-previewtenet-compatibility

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions