Home > database >  Conditional ?: operator for ComboBox
Conditional ?: operator for ComboBox

Time:12-16

I want to add following code into the following code into Form1_Load function so that if serial port COM port is attached, the combobox will choose it automatically.

But using conditional ?: statement, I can't figure out how to do it.

So if combobox contains more than 1 item, it choose 2nd item of combobox. Otherwise it choose 0th item

comboBox1.Items.Count > 1 ? comboBox1.SelectedIndex = 2 : comboBox1.SelectedIndex = 0;

CodePudding user response:

It's suppose to be comboBox1.SelectedIndex = comboBox1.Items.Count > 1 ? 2 : 0

  • Related