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);
}
}
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.
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);
}
Yes, try combobox.Clear(). You can find docs for Gtk# at http://docs.go-mono.com/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.