[英]MONO GTK#: Trying to remove text in ComboBox and then prepend new text to the ComboBox but some of the old text remains
我試圖首先刪除ComboBox中的所有內容。 然后將文本添加到文本中,但仍保留一些舊文本。 有沒有辦法重置或清除ComboBox? 或者我怎樣才能做到最好?
public void GetBadgeName ()
{
try
{
int i = 0;
while (i < 200)
{
cmb_SelectBadge.RemoveText(i);
++i;
}
string connectionString = "URI=file:SIGN.sqlite";
IDbConnection dbcon;
dbcon = (IDbConnection) new SqliteConnection(connectionString);
dbcon.Open();
IDbCommand dbcmd = dbcon.CreateCommand();
string sql =
"SELECT BadgeName " +
"FROM Badge";
dbcmd.CommandText = sql;
IDataReader reader = dbcmd.ExecuteReader();
while(reader.Read()) {
string BadgeName = reader.GetString (0);
cmb_SelectBadge.PrependText(BadgeName);
}
reader.Close();
reader = null;
dbcmd.Dispose();
dbcmd = null;
dbcon.Close();
dbcon = null;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
我想通了。 只需創建一個新的空ListStore(我稱之為ClearList),然后使combobox.Model等於ClearList。 然后將文本正常添加或附加到組合框中。
ListStore ClearList = new ListStore(typeof(string),typeof(string));
cmb_SelectBadge.Model = ClearList;
// This example retrieves each BadgeName from the Badge table (see question)
while(reader.Read()) {
string BadgeName = reader.GetString (0);
cmb_SelectBadge.PrependText(BadgeName);
}
是的,嘗試使用combobox.Clear()。 你可以在http://docs.go-mono.com/找到Gtk#的文檔。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.