2011-03-06 145 views
1

这是我如何填充组合框:重新填充组合框

 foreach(string s in entries) 
     { 
      string[] fields = someSplit(s); 
      threadComboBox.AppendText(fields[0]); 
     } 

如何我会删除所有项目,并添加新的?我尝试过拨打Clear(),但是虽然它删除了旧值,但新值不会被添加。

+0

什么是'threadComboBox'?一个简短但完整的例子会有帮助... – 2011-03-06 19:11:56

+0

一个'ComboBox'包含一些线程(如在bbs中的主题)。 – Gerals 2011-03-06 19:13:08

+1

你在通过你的'foreach'循环之前调用'Clear()'*吗? – Farray 2011-03-06 19:20:01

回答

3

尝试

threadComboBox.Clear(); 
    ListStore store = new ListStore(typeof (string)); 
    threadComboBox.Model = store; 

    foreach(string s in entries) 
    { 
     string[] fields = someSplit(s); 
     store.AppendValues (fields[0]);   
    } 
1

接受的答案本身并不为我工作。我不得不使用FAQ的片段:

cb.Clear(); 
CellRendererText cell = new CellRendererText(); 
cb.PackStart(cell, false); 
cb.AddAttribute(cell, "text", 0); 
ListStore store = new ListStore(typeof (string)); 
cb.Model = store; 

//now this works: 
cb.AppendText("test");