组合框中填充的值即使在刷新组合框时也不会更新

本文关键字:组合 更新 刷新 填充 | 更新日期: 2023-09-27 18:28:43

我的问题是:我有一个组合框,我使用以下代码填充它。它填充得很好,但我希望它刷新并只获取具有的值

deliverystatus ='pending'

在数据库中(组合框只为那些名为"传递状态"的字段设置为"挂起"的详细信息填充),在我单击发送按钮后,数据库将用更新

deliverystatus=approved

但是组合框仍然显示刚刚更新的值i,即

deliverystatus =approved

(点击发送后)。但我希望在我发送详细信息后,从组合框中自动删除交货状态为"已批准"的值。

using (SqlConnection se = new SqlConnection("Data Source=HP-HP;Initial Catalog=MIND;Integrated Security=True"))
{
  try
  {
    SqlDataAdapter d = new SqlDataAdapter("select  UniqueID from deliverydata where delivery_status='Pending' and approvedby=(select name from TEAM where emailid='" + attach.newvalue() + "')", se);
    DataSet dt = new DataSet();
    d.Fill(dt);
    comboBox_deliverytypedisp.DataSource = dt.Tables[0]; /// assing the first table of dataset
    comboBox_deliverytypedisp.DisplayMember = "UniqueID";
  }
  catch (Exception ex)
  {
    // write exception info to log or anything else
    MessageBox.Show(ex.ToString());
  }
}

组合框中填充的值即使在刷新组合框时也不会更新

您是否先尝试清除它?

comboBox_deliverytypedisp.DataSource = null

我记得用DataGridView.DataSource做过类似的事情,因为它不会以其他方式刷新。

 dt.Tables[0].DefaultView.RowFilter = "deliverystatus ='pending'";
 comboBox_deliverytypedisp.DataSource = dt.Tables[0];