title: Combo box for serial port
body: <p>I'm doing a project for serial port.. </p>
  
  <p>I need to select the available com port from the combo box. </p>
  
  <p>but i cant get it.. And i needed some help~</p>
  
  <p>Here's my code.. its in C#:</p>
  
  <p>btn_Open is a button to activate the serial port</p>
  
  <pre><code>    private void btnOpen_Click(object sender, EventArgs e)
      {
          string [] myPort;
  
          int COM1 = cbCommPorts.SelectedIndex;
          int COM2 = cbCommPorts.SelectedIndex;
          int COM3 = cbCommPorts.SelectedIndex;
          Object selectedItem = serialPort1.PortName;
  
          myPort = System.IO.Ports.SerialPort.GetPortNames();
          cbCommPorts.Items.AddRange(myPort);
  
          serialPort1.PortName = cbCommPorts.SelectedItem.ToString();
          serialPort1.BaudRate = 115200;
  
          if (serialPort1.IsOpen) {
              serialPort1.PortName = cbCommPorts.SelectedItem.ToString();
  
              serialPort1.Open();
              btnTransmit.Enabled = true;
              btn2.Enabled = true;
              btn3.Enabled = true;
          }
  </code></pre>
  
  <ol>
  <li><p>cbCommPorts is the name i got for the Combo Box</p>
  
  <p>private void cbCommPorts_SelectedIndexChanged(object sender, EventArgs e)
      {
          int COM1 = cbCommPorts.SelectedIndex;
          int COM2 = cbCommPorts.SelectedIndex;
          int COM3 = cbCommPorts.SelectedIndex;
          Object selectedItem = serialPort1.PortName;</p>
  
  <pre><code>    MessageBox.Show("COM PORT: " + selectedItem.ToString() + " Selected");
  }
  </code></pre></li>
  </ol>
  
  <p>Is there any problem to my codes? Thanks..</p>