我不明白以下简单代码有什么问题。它所做的只是获取一个列表并将其显示在 datagridview 中。这是我得到的错误:
错误 1 可访问性不一致:返回类型“System.Collections.Generic.List”比方法“WindowsFormsApplication10.Form1.FillGridView()”更难访问
另外,有没有办法将您的列表、数组列表等转换为数据集类型?
public partial class Form1 : Form
{
public Form1 ()
{
InitializeComponent ();
}
public List<Student> FillGridView ()
{
List<Student> l = new List<Student> ();
l.Add (new Student { Fname="bloke", Lname="lll", Contact=293489485});
l.Add (new Student { Fname = "dog", Lname = "assdf", Contact = 35345 });
l.Add (new Student { Fname = "mary", Lname = "sdff", Contact = 6456 });
l.Add (new Student { Fname = "john", Lname = "sdfsdf", Contact = 45656 });
return l;
}
private void Form1_Load ( object sender, EventArgs e )
{
dataGridView1.DataSource = this.FillGridView ();
}
private void button1_Click ( object sender, EventArgs e )
{
}
}