comBox控件绑定数据库字段后,在窗体的Load事件之前就已经触发SelectedIndexChanged了,这时可以加一个标识,让其在Load事件之后激发。
bool flag;private void Education_Training_Load(object sender, EventArgs e){ MyDBase DB = new MyDBase(DBUser.sserver, DBUser.DBName, DBUser.suser, DBUser.spasswd); DataSet DS = DB.GetRecordset("select distinct (year(date)) as date from education_train where PID=1");comboBox_Year.DataSource = DS.Tables[0];comboBox_Year.DisplayMember = "date";comboBox_Year.ValueMember = "date";flag = true;DB.DBClose();}private void comboBox_Year_SelectedIndexChanged(object sender, EventArgs e){if (!flag) return;MyDBase DB = new MyDBase(DBUser.sserver, DB