C# 重新填充组合框

C# 重新填充组合框,c#,mono,gtk,C#,Mono,Gtk,这是我填充组合框的方式: foreach(string s in entries) { string[] fields = someSplit(s); threadComboBox.AppendText(fields[0]); } 如何删除所有项目并添加新项目?我尝试调用了Clear(),但是虽然它确实删除了旧值,但没有添加新值。试试看 threadComboBox.Clear();

这是我填充组合框的方式:

        foreach(string s in entries)
        {
            string[] fields = someSplit(s);
            threadComboBox.AppendText(fields[0]);
        }
如何删除所有项目并添加新项目?我尝试调用了
Clear()
,但是虽然它确实删除了旧值,但没有添加新值。

试试看

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

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


被接受的答案本身并不适合我。我不得不使用以下文件中的片段:


被接受的答案本身并不适合我。我不得不使用以下文件中的片段:


什么是
threadComboBox
?一个简短但完整的示例会很有帮助…一个包含一些线程的
组合框
(如bbs上的主题)。在执行
foreach
循环之前,您是否调用
Clear()
?什么是
线程组合框
?一个简短但完整的示例会很有帮助……一个包含一些线程(如bbs上的主题)的
组合框。在执行
foreach
循环之前,您是否正在调用
Clear()
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");