combox绑定的数据是从数据库查询出来的:
private void Bind() { try { BLL.BLL_t_user bll = new BLL.BLL_t_user (); DataSet ds = bll.GetList(0, "id,name"); if (ds != null) { this.combox1.DataSource = ds.Tables[0]; this.combox1.ValueMember = "id"; this.combox1.DisplayMember = "name"; this.combox1.SelectedIndex = 0; } else { this.combox1.DataSource = null; } } catch (Exception ex) { } }
清空combox的时候必须先清除datasource再clear:
//清空combox this.combox1.DataSource = null; combox1.Items.Clear();
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/231805.html原文链接:https://javaforall.net
