Click here to Skip to main content
15,900,973 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Dear Friends


I am Trying To Load Serial port numbers of my system in combo box com1 and com2 are loaded in correct form but other loaded like COM6 COM7 i am not getting the what is that box Symbol after no

this Code I am using to load the serial port

C#
string[] ports = SerialPort.GetPortNames();


            foreach (string port in ports)
            {
                cboPorts.Items.Add(port);
            }
Posted
Updated 26-Nov-13 0:14am
v2
Comments
OriginalGriff 26-Nov-13 6:08am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Without the code fragment you are using to load the combo box, we can't even begin to help you fix this.
Use the "Improve question" widget to edit your question and provide better information.
murkalkiran 26-Nov-13 6:15am    
Sorry for incomplete question this is the code i am using
string[] ports = SerialPort.GetPortNames();


foreach (string port in ports)
{
cboPorts.Items.Add(port);
}
murkalkiran 27-Nov-13 0:28am    
Thanku very much OriginalGriff
murkalkiran 28-Nov-13 2:19am    
Hi Friend Your Solution Is working fine, but now i tried in windows 8 but there are serial port in windows 8 do have any idea how it can be done in windows 8
Fortyseven203 16-Aug-15 23:44pm    
Having this same problem, myself. The gibberish is a single, seemingly random character, and coming straight from the GetPortNames() method. (So it's not related to the ComboBox.)

string[] ports = SerialPort.GetPortNames();

if ( ports.Length == 0 ) {
MessageBox.Show( "No serial ports reported.", "Device Error" );
return;
}

foreach ( string port in ports ) {
cbPort.Items.Add( port );
}

1 solution

You need to look at your system as a whole, and examine the ports you have fitted - it would seem that some of them are using drivers which report the name incorrectly - we can't duplicate that here as we do not have access to your system.

If you can't do anything about it, then one way to "hide" the problem would be to use a regext to get rid of any "rubbish" at the end.
C#
string[] ports = SerialPort.GetPortNames();
foreach (string port in ports)
    {
    string cleaned = Regex.Match(port, @"COM\d+").Value;
    cboPorts.Items.Add(cleaned);
    }
 
Share this answer
 
Comments
Fortyseven203 16-Aug-15 23:46pm    
In my case, that explanation doesn't quite work. I've used other serial diagnostic tools and the ports are listed fine.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900