將數據綁定到窗體上單獨的控件
private void Dept_Load(object sender, EventArgs e)
{
DataTable table=nwData.Customers;
txtDeptno.DataBindings.Add("Text", table, "DeptNo",true);
txtDeptname.DataBindings.Add("Text", table, "Deptname",true);
txtCreator.DataBindings.Add("Text", table, "Creator",true);
txtCreateDate.DataBindings.Add("Text", table, "CreateDate",true);
txtModifier.DataBindings.Add("Text", table, "Modifier",true);
txtModifyDate.DataBindings.Add("Text", table, "ModifsyDate",true);
txtPosition.DataBindings.Add("Text", table, "Position",true);
txtTel.DataBindings.Add("Text", table, "Tel",true);
txtDescription.DataBindings.Add("Text", table, "Description",true);
txtSerialNo.DataBindings.Add("Text", table, "SerialNo",true);
}
1、Add方法的第一個參數是要綁定的控件的屬性的名稱,它可以是控件顯示的任何公共屬性
2、第二個參數是包含要綁定的數據的數據源,它可以是多種形式的數據集合之一。在程序代碼中,首先,它存儲了局部變量類型DataTable中的表引用,然後將局部變量作為數據參數傳遞給Add方法;
3、第三個參數是數據源中的數據成員名稱,這個參數也可以表現為多種形式,取決何種形式取決數據源的種類以及數據源中的數據成員所在的位置,
4、最後一個參數設置為true,它是一個標識是否自動格式化顯示的標誌。v