MONO GTK#:尝试删除组合框中的文本,然后将新文本添加到组合框中,但仍保留一些旧文本
我试图首先删除组合框中的所有内容。然后在其前面添加文本,但保留一些旧文本。有没有办法重置或清除组合框?或者我怎样才能最好地实现这一目标?
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);
}
}
I am trying to first remove everything in the ComboBox. And then prepend text to it, but some of the old text remains. Is there a way to RESET or CLEAR the ComboBox? Or how can I best achieve this?
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);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我明白了这一点。只需创建一个新的空ListStore(我称之为ClearList),然后使combobox.Model 等于ClearList。然后像往常一样将文本添加到组合框的前面或后面。
I figured this out. Simply create a new empty ListStore (I call it ClearList) and then make the combobox.Model equal to the ClearList. Then prepend or append the text as normal to the combobox.
是的,尝试组合框.Clear()。您可以在 http://docs.go-mono.com/ 找到 Gtk# 的文档
Yes, try combobox.Clear(). You can find docs for Gtk# at http://docs.go-mono.com/