2013年12月13日。
我有一个List<>想要绑定到DataGridView。 它有效,但今天它不起作用。
public class ExamResult
{
public string ID;
public bool Result;
public bool ReviwerResult;
public string QuestionFileName;
}
然后创建List:
List<ExamResult> result = new List<ExamResult>();
创建ExamResult实例并为其成员分配值,然后将其添加到List:
//Create a Instance of ExamResult:
ExamResult examResult = new ExamResult();
//Assign Value to members:
examResult.ID="001";
examResult.Result=false;
examResult.ReviewerResult=true;
examResult.QuestionFileName = string.empty;
//Add examResult Instance to List<ExamResult>
result.Add(examResult);
然后尝试将它绑定到我的WinForm应用程序上的DataGridView。
this.DataGridView.AutoGenerateColumns = true;
this.DataGridView.DataSource = result;
但是DataGridView不显示任何东西!!!
我发誓这段代码有效,现在它无法正常工作!不改变代码。
有什么问题?
答案 0 :(得分:5)
将您的班级更改为使用属性而不是字段:
public class ExamResult
{
public string ID {get; set;}
public bool Result {get; set;}
public bool ReviwerResult {get; set;}
public string QuestionFileName {get; set;}
}