我不明白下面的简单代码有什么问题。它所做的只是获取一个列表并将其显示在数据 GridView 中。这是我得到的错误:
Error 1 Inconsistent accessibility: return type 'System.Collections.Generic.List' is less accessible than method '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 )
{
}
}
最佳答案
你的方法需要公开吗?看起来您的学生类(class)不是公开的,因此将其列表返回给任何公开调用者是不一致的。看起来,您的方法可以是私有(private)的。
private List<Student> FillGridView()
关于c# - 无法使用泛型列表填充数据 GridView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15542987/