datagried绑定list不现实值
本帖最后由 u012994978 于 2013-11-29 12:25:41 编辑
//窗体加载事件
public List<SE> li = new List<SE>();
private void Form1_Load(object sender, EventArgs e)
{
SE a = new SE();
a.name = "zjfsf";
a.sex = "男";
a.age = 45;
a.gonghao = "23232";
li.Add(a);
this.dgv2.DataSource = new BindingList<SE>(li);
}
//SE类
public class SE
{
public string gonghao;
public string name;
public int age;
public string sex;
public gender da;
}
自动生成列。但是就是不行。
------解决方案--------------------楼主和1楼大神方法都对;问题在于你用的类,不要用字段,用属性就可以了;
/// SE类
public class SE
{
private string _gonghao;
private string _name;
private int _age;
private string _sex;
//private gender da;
public string gonghao
{
get { return _gonghao; }
set { _gonghao = value; }
}
public string name
{
get { return _name; }
set { _name = value; }
}
public int age
{
&nbs