-1

In C#, I have some comboboxes functioning as dropdown lists. The first value in the collection is the one I want to show as default to the user. Therefore, I added a line to the designer file, so that upon load, first value, aka index 0, is shown.

combobox1.SelectedIndex = 0;

It works! I do the same for every other combobox in my app, however, this keeps disappearing from the designer file. How can I fix this?

Thanks in advance.

ElPeta
  • 61
  • 1
  • 9
  • 2
    The designer file is not for you to edit - there is a comment in the file to that effect. The Designer is constantly rewriting the designer file to reflect changes it needs to make. Move your code to someplace such as the form load event – Ňɏssa Pøngjǣrdenlarp Jul 31 '20 at 18:22
  • Thanks for your comment! Funny thing is that I have set some properties directly in code in the design file and they remain there. Don't know why I can't make these stick. – ElPeta Jul 31 '20 at 21:35

1 Answers1

0

As mentioned in comments:

The designer file is not for you to edit - there is a comment in the file to that effect. The Designer is constantly rewriting the designer file to reflect changes it needs to make. Move your code to someplace such as the form load event

As the programming noob I am, I overlooked adding an OnLoad method with the selectedindex for each combobox. That solved my problem!

Ňɏssa Pøngjǣrdenlarp
  • 38,411
  • 12
  • 59
  • 178
ElPeta
  • 61
  • 1
  • 9