![](/img/trans.png)
[英]The Data Bound ComboBox doesn't update until the application is restarted
[英]The Data Bound ComboBox doesn't update
我有一个包含项信息的DataTable和一个用于订购项的表单。 在“订单”表单上,有一个显示项目名称的组合框:
void fillComboItem()
{
string constring = @"Data Source=|DataDirectory|\LWADataBase.sdf";
string Query = "select * from stockTBL; ";
SqlCeConnection conDataBase = new SqlCeConnection(constring);
SqlCeCommand cmdDataBase = new SqlCeCommand(Query, conDataBase);
SqlCeDataReader myReader;
try
{
conDataBase.Open();
myReader = cmdDataBase.ExecuteReader();
while (myReader.Read())
{
string sName = myReader.GetString(myReader.GetOrdinal("Item Name"));
comboItem.Items.Add(sName);
}
//displays a system error message if a problem is found
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
当我将数据插入到DataTable中时,它不会更新Order表单中的ComboBox,并且我必须重新启动应用程序才能对其进行更新。 如何“刷新”组合框?
据我了解,您正在谈论的是在数据库更改时更新UI。 您不能通过显式调用数据绑定函数(在您的情况下为fillComboItem)来做到这一点,当您想要更新组合框时,例如,当用户打开网格或单击时。 或者,您可以对数据库执行ping操作,但这不是一种轻量级的方法,应谨慎使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.