Click here to Skip to main content
15,884,629 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a combo box in table layout panel .I want to add the existing serial ports to it.But it doesn't show my ports in the items.It shows nothing.(I have to mention that when the combo box wasn't in table layout panel it worked, but now it doesn't).

What I have tried:

C#
private void Form1_Load(object sender, EventArgs e)
        {
            string[] ports = SerialPort.GetPortNames();
            cBoxComPort.Items.AddRange(ports);
        }
Posted
Updated 15-Aug-22 0:12am
Comments
Richard MacCutchan 15-Aug-22 5:06am    
Use the debugger to check that GetPortNames actually returns a string array.

1 solution

If it's not showing any items, then GetPortNames is returning an empty array.
If you look at the documentation, it says this:
Remarks
The order of port names returned from GetPortNames is not specified.

Use the GetPortNames method to query the current computer for a list of valid serial port names. For example, you can use this method to determine whether COM1 and COM2 are valid serial ports for the current computer.

The port names are obtained from the system registry (for example, HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM). If the registry contains stale or otherwise incorrect data then the GetPortNames method will return incorrect data.

So start by looking at the registry and see what it says the computer has.

Sorry, but we can't help you with this one - we have no access to your system!
 
Share this answer
 

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