I have problem clearing a previously added ComboBox items. I have a method that when called, fills a combobox with the available serial ports of the system:
private void RefreshPortNames ()
_portNames = System.IO.Ports.SerialPort.GetPortNames();
//combobox1.Clear(); //This makes combobox do nothing!
foreach (var port in _portNames)
if(port.ToLower().Contains("usb")) //Check if port is usb
The problem is Clear() method will make combobox to reset and it does not gets populated with any item.
If I remove it the combobox it works good but everytime I call this method, the items will be appended to the old ones and I will have a long list! I want the comobox to be cleared before adding new items in it.
Can someone please tell me what is the correct way of doing this?