I’ve written this code to change the serialport name:
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
serialPort1.PortName = (string)comboBox1.SelectedValue;
}
catch (Exception)
{
MessageBox.Show("The SerialPorts's Name Does Not Change !! ");
}
}
The result is that I get an Exception. The SerialPort‘s name never changes.
To use the
SelectedValueMr. JaredPar MSFT explained ComboBox SelectedItem, SelectedValue, SelectedWhat???.I guess, your trying get the
PortNamenot theSelectedValueSolution:
or
your trying get the
SelectedValuenot thePortNameSolution:
Try to check your properties of
ComboBoxWhere: Display Member is your PortName Value Member is your PortId or SelectedValue