我的代码如下:
IList<Users> myData = new List<Users>();
myData = HelperUsers.GetUsersList(); // return IList<Users>
BindingSource bsUsers = new BindingSource { DataSource = myData };
dataGridViewUsers.DataSource = bsUsers;
dataGridViewUsers.Columns["Name"].HeaderText = "Name";
dataGridViewUsers.Columns["LastName"].HeaderText = "Last name";
dataGridViewUsers.Invalidate();
在调试中仍然可以完美工作,但是当编译为发布时,会出现以下错误“对象引用未设置为对象的实例”。在行中:
dataGridViewUsers.Columns["Name"].HeaderText = "Name";
谢谢