如何通过单击按钮删除项目后刷新ComboBox? [英] How to refresh ComboBox after delete an Item by Clicking On A Button?

查看:133
本文介绍了如何通过单击按钮删除项目后刷新ComboBox?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  private   void  button1_click(对象发​​件人,EventArgs e)
{
sql连接Conn = sql连接( Server =。; DataBase = BooksDB; Integrated Security = True);
sqlCommand Comm = new sqlCommand( 删除来自书籍的作者= N' + cbxAuthor.SelectedValue + ',conn );
conn.open();
Comm.ExecuteNonQuery();
MessageBox.Show( Sucess);
conn.Close();
}

解决方案

删除操作后,再次绑定组合框


显然,在您加载页面时,您已编写了用于绑定该组合框的代码。



您只需要检查对话框结果,如果没有问题,那么通过调用您编写的第一次绑定它的方法来重新组合您的组合框。

 private void button1_click(object sender , EventArgs e)
{
sql connection Conn= new sql connection("Server=. ; DataBase=BooksDB ; Integrated Security =True");
sqlCommand Comm =  new sqlCommand ("Delete From Books Where Author = N'"+cbxAuthor.SelectedValue + "'" , conn);
conn.open();
Comm.ExecuteNonQuery();
MessageBox.Show("Sucess");
conn.Close();
} 

.

解决方案

After the delete operation, bind the combobox again


Obviously Somewhere you have written the code to bind that combobox when your page is loaded.

You just need to check the dialog result and if it is OK then REBIND your combobox by calling the same method you have written to bind it first time.


这篇关于如何通过单击按钮删除项目后刷新ComboBox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆