My application contains a ComboBox from which the user can delete items. When the program starts, it populates the ComboBox from the list of lines read from the configuration file.
Here is the code to add items:
// version list is an array of strings foreach (string version in versionList) { versionComboBox.Items.Add(version); } if (versionComboBox.Items.Count > 0) { versionComboBox.SelectedIndex = 0; }
Here is a screenshot of the combo box after filling it out:

If the user clicks the Delete button, the program removes the selected item from the ComboBox using the following code:
if (versionComboBox.SelectedIndex >= 0) { versionComboBox.Items.Remove(versionComboBox.SelectedItem); } if (versionComboBox.Items.Count > 0) { versionComboBox.SelectedIndex = 0; }
Here is a screenshot of the combo box after removing several items:

The problem I ran into is when the last item is deleted, the ComboBox resizes to the size when it was originally populated. There are no elements in the ComboBox, but it measures as if they were.
Here is a screenshot after deleting all the elements:

As you can see, the size is too large. I think that after all the elements have been cleared, it will look like this:

Any ideas as to why this is happening?
source share