GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Tue Sep 02, 2014 9:08 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: How to remove ComboBox items
PostPosted: Wed Sep 12, 2012 9:12 am 
Offline

Joined: Wed Sep 12, 2012 8:52 am
Posts: 1
Hi all,

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:
Code:
   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
            combobox1.AppendText(port);
      }
   }
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?

Thanks.


Top
 Profile  
 
 Post subject: Re: How to remove ComboBox items
PostPosted: Wed Sep 12, 2012 3:16 pm 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hello and welcome to the GTK+ forums!

Exact method you need to employ here depends on how you initially create your combo box, but what you need to do is clear not the combo box but it's data source - GtkTreeModel associated with it. If you recreate the whole contents, it may even be simpler to replace model altogether.

Cheers,
Tadej


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group