读书人

listbox的重新载入有关问题

发布时间: 2012-01-03 22:16:06 作者: rapoo

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

读书人网 >C#

热点推荐