In WinForm, I have a ComboBox. I am trying to do something like this.
When ComboBox has only 1 item, that item should be set as \"Selected Text\" for ComboBox, and w
You may use
if (ComboBox1.Items.Count>0) { ComboBox1.SelectedIndex=0 }
if combobox has only one item, then you can use below code
comboBox1.SelectedIndex =0;
if combobox has multiple item, and you need to select a particular item... change only the index, index will start with 0, if you need to show second item, then the index will be 1
comboBox1.SelectedIndex =1;
If I understand it the right way, you want the first item of the combobox to be selected/shown in comboBox.
This is quite easy:
comboBox1.SelectedIndex = 0; //This will select the first item in the combobox (zero based numbering)
To set it right after the form is shown simply put it after
InitializeComponent();
of the appropriate form.