Question Names of COms

dibrony

Member
Joined
Oct 23, 2010
Messages
6
Programming Experience
5-10
Hi all,

i am using the below code in VB.Net to load the available serial ports :

COMsComboBox.Items.Clear()
Dim i As Integer
For i = 1 To My.Computer.Ports.SerialPortNames.Count
COMsComboBox.Items.Add(My.Computer.Ports.SerialPortNames(i - 1))
Next


i also want to load their names as seen in the "device manager", anyone know how to do it ??

Thank you guys.

Regards
Rony
 
Consider using For-Each loop, it is more readable:
VB.NET:
For Each port In My.Computer.Ports.SerialPortNames
    COMsComboBox.Items.Add(port)
Next
Also consider these easier options, when input items available to add as range:
VB.NET:
ComboBox1.Items.AddRange(My.Computer.Ports.SerialPortNames.ToArray)
Or if list is finite:
VB.NET:
ComboBox1.DataSource = My.Computer.Ports.SerialPortNames
To me the names was exactly the same as in Device Manager, what do you mean?
 
Back
Top