Combox 设定ValueMember时提示 未将对象引用设置到对象的实例
DataTable dsProject = settings.ProjectsList().Tables[0];DataRow row = dsProject.NewRow();
row["id"] = 0;
row["name"] = "Select a project please";
dsProject.Rows.InsertAt(row,0);
DataTable table = dsProject.Copy();
cboChoseDefaultProject.DataSource = table;
cboChoseDefaultProject.DisplayMember = "name";
cboChoseDefaultProject.ValueMember = "id";
程序每次跑到cboChoseDefaultProject.ValueMember = "id";都提示未将对象引用设置到对象的实例
新来的,没有可以散 :) --------------------编程问答-------------------- DataRow row = dsProject.NewRow();
row["id"] = 0;
row["name"] = "Select a project please";
dsProject.Rows.InsertAt(row,0);
DataTable table = dsProject.Copy();
把这几句去掉!直接绑!
--------------------编程问答-------------------- 去掉之后还是报未将对象引用设置到对象的实例 --------------------编程问答-------------------- 把cboChoseDefaultProject.DataSource = table; 放后面
实在不行
DataTable dt = settings.ProjectsList().Tables[0];
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
cmbDepartment.Items.Add(dt.Rows[i]["显示的字段名"].ToString());
}
} --------------------编程问答-------------------- 谢谢,放后面果然可以,只是为什么呢?
补充:.NET技术 , C#