vs2003中將數據邦定到combobox中包含空行的方法

方法一:

//取得所有部門信息

   dsdept = myFind.GetDept(out ErrMsg);

//插入空行
   cmbDept.ValueMember.Insert(0,"");
   cmbDept.DisplayMember.Insert(0,"");

//讀取其他hang
   for (int i=1;i<=dsdept.Tables[0].Rows.Count;i++)
   {
    cmbDept.ValueMember.Insert(i,dsdept.Tables[0].Rows[i]["DEPTCODE"].ToString().Trim());
    cmbDept.DisplayMember.Insert(i,dsdept.Tables[0].Rows[i]["DEPTNAME"].ToString().Trim());
   } 

方法二:  

dsdept = myFind.GetDept(out ErrMsg);

 cmbDept.DataSource = dsdept.Tables[0];
   cmbDept.DisplayMember = "DEPTNAME";
   cmbDept.ValueMember = "DEPTCODE";

//插入空行
   cmbDept.SelectedItem = null;
   cmbDept.SelectedValue = "";
   cmbDept.Text = "";

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章