wataru lover

wataru lover

  • NA
  • 1
  • 1.4k

friendly port name combobox c# Windows Form VS2013

May 17 2015 3:54 PM

 I have a question about friendly name I read a lot (really a lot) about how to get the friendly name. I even used the WMICodeCreator I have a code to put. But actually I don't understand how to add this to my combobox menu. here under is my code. Actually this one is showing the available COM port on the computer, but I would like to show the friendlyname of this one to make my application easier to use. How can I do to display friendlyname instead of "COMx" by using this?

ManagementObjectSearcher is making error when I'm using it  (even if I'm adding using System.Management;)
 
I'm using Windows Form application on C#.
 public partial class Form1 : Form
{
    private SerialPort myport;
    public Form1()
{
   InitializeComponent();
    myport = new SerialPort();
  }
private void portbox_DropDown(object sender, EventArgs e)
{
   string[] ports = SerialPort.GetPortNames();
   portbox.Items.Clear();
  
foreach (string port in ports)
{
    portbox.Items.Add(port);
}
}
private void butvalidate_Click(object sender, EventArgs e)
{
myport.BaudRate = 9600;
myport.PortName = portbox.SelectedItem.ToString();
myport.Open(); }

In advance thanks for your help, I'm kinda news in coding that why I'm asking.