C # Combo Box only kits in debug mode

I am writing an application in C # (VS Express 2015) and have a combo box that I want to pre-populate with a saved value. I cannot get combobox to use the value I'm trying to set. I created a new project to demonstrate this error.

The main code is given below. Another file declares a LayoutPanel table. The drawComboBox function should add a combo box to the panel with the specified option and row specified.

    public Form1()
    {
        InitializeComponent();
        drawComboBox(Options.Blue, 0);
    }

    public enum Options
    {
        Unset,
        Blue,
        Yellow,
        Red
    };

    private void drawComboBox(Options SelectedOption, int row)
    {
        System.Windows.Forms.ComboBox colorCombo = new System.Windows.Forms.ComboBox();
        colorCombo.DataSource = Enum.GetValues(typeof(Options));
        colorCombo.Name = "colorCombo";
        this.tableLayoutPanel1.Controls.Add(colorCombo, 0, row);
        colorCombo.SelectedItem = Options.Yellow;
    }

, "", , colorCombo Locals , . , , , , , .

, .

+4
1

, , , -

, , , .

 private void drawComboBox(Options SelectedOption, int row)
    {
        System.Windows.Forms.ComboBox colorCombo = new System.Windows.Forms.ComboBox();
        colorCombo.Name = "colorCombo";
        this.tableLayoutPanel1.Controls.Add(colorCombo, 0, row);

        colorCombo.DataSource = Enum.GetValues(typeof(Options));
        colorCombo.SelectedItem = Options.Yellow;


    } 

,

"unset"

        colorCombo.DataSource = Enum.GetValues(typeof(Options));
        this.tableLayoutPanel1.Controls.Add(colorCombo, 0, row);

,

  this.tableLayoutPanel1.Controls.Add(colorCombo, 0, row);
        colorCombo.DataSource = Enum.GetValues(typeof(Options)); 
0

Source: https://habr.com/ru/post/1610189/


All Articles