日期:2014-05-19  浏览次数:20908 次

listbox的重新载入问题
用Listbox绑定了数据库代码如下:
SqlConnection   con   =   new   SqlConnection( "Data   Source=.;Initial   Catalog=TestOnline;Integrated   Security=True ");
                       
SqlDataAdapter   da   =   new   SqlDataAdapter( "select   DepName,DepID,DepAdminTeacherID   from   TblDepartment ",   con);
                        DataTable   dt   =   new   DataTable( "DepTable ");
                     
                        dt   =   ds.Tables[ "DepTable "];

                        DataSet   ds   =   new   DataSet();
                        da.Fill(ds,   "DepTable ");
      this.LstDep.DataSource   =   dt;
                        this.LstDep.DisplayMember   =   "DepName ";
                        this.LstDep.ValueMember   =   "DepID ";
                        想在新加入一条记录后即时的显示出来,但是试图用clear方法清除掉列表框里原有的记录再重新绑定时,提示“设置了datasource属性以后无法修改”
 谁能给我个意见啊?


------解决方案--------------------
用this.LstDep.DataSource = dt;
this.LstDep.DisplayMember = "DepName ";
this.LstDep.ValueMember = "DepID ";
绑定后,不能修改

建议用For循环加入Item