gpt4 book ai didi

c# - 单声道 GTK# : Trying to remove text in ComboBox and then prepend new text to the ComboBox but some of the old text remains

转载 作者:行者123 更新时间:2023-11-30 17:15:40 26 4
gpt4 key购买 nike

我试图先删除 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);
}

关于c# - 单声道 GTK# : Trying to remove text in ComboBox and then prepend new text to the ComboBox but some of the old text remains,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7850629/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com