Combo Box Size Issue After All Items Are Removed

前端 未结 4 860
梦毁少年i
梦毁少年i 2021-01-13 04:37

My application contains a ComboBox that the user can delete items from. When the program starts up it populates the ComboBox from a list of strings read in from a configurat

相关标签:
4条回答
  • 2021-01-13 05:17

    To clear your combo box you can add this:

    if (versionComboBox.Items.Count == 0)
    {
        versionComboBox.Text = string.Empty;
        versionComboBox.Items.Clear();
        versionComboBox.SelectedIndex = -1;
    }
    

    Another approach is to manipulate the items in the data source and rebind the control each time (a lot less for you to worry about).

    0 讨论(0)
  • 2021-01-13 05:20

    Try to use this at the end of your code when you are filling the combobox items:

    comboBoxNumTreno.IntegralHeight = true; // auto fit dropdown list
    

    Then to clear it up:

    comboBoxNumTreno.ResetText();
    comboBoxNumTreno.Items.Clear();
    comboBoxNumTreno.SelectedIndex = -1;
    comboBoxNumTreno.DropDownHeight = 106; // default value
    comboBoxNumTreno.IntegralHeight = false; 
    
    0 讨论(0)
  • 2021-01-13 05:24

    I know this is an old post, but it took me a long time to figure this out and I wanted to let anyone in the future know. After you clear your combo box just do a blank add items and it resets the height.

    comboBox1.Items.Clear();
    comboBox1.Items.Add("");
    
    0 讨论(0)
  • 2021-01-13 05:24

    set DropDownHeight property to fix size

     versionComboBox.DropDownHeight = 106; // default value
    
    0 讨论(0)
提交回复
热议问题