Repopulate a combo box

橙三吉。 提交于 2019-12-24 09:20:46

问题


This is how I populate the combo box:

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

How would I remove all items and add new ones? I tried calling Clear(), but while it does remove old values, new ones don't get added.


回答1:


try

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

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



回答2:


The accepted answer did not work for me by itself. I had to use the snippet from the 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");


来源:https://stackoverflow.com/questions/5212739/repopulate-a-combo-box

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!