Search code examples
c#comboboxinvisible

ComboBoxes won't show up


Why won't the comboboxes show up on the form? (They are invisible)

private ComboBox[] statsValues;

public frmMain()
{
    InitializeComponent();
    statsValues = new ComboBox[5];
    for (byte b = 0; b < statsValues.Length; b++)
    {
        statsValues[b] = new ComboBox();
        statsValues[b].Location = new System.Drawing.Point(300, 300);
        statsValues[b].DropDownStyle = ComboBoxStyle.DropDownList;
        statsValues[b].Visible = true;
        statsValues[b].Enabled = true;
    }
}

Solution

  • The controls created dinamically in this way need to be added to the Form controls' collection

    this.Controls.AddRange(statsValues);
    

    As a side note, you are creating 5 combox all at the same position. When you show them on your form you won't be able to see all of them, only the last one on the top of the other fours