我在一个类中加载了一个List,它从.txt文件加载数据,然后将数据存储在另一个包含构造函数和其他类的对象中。在我的表单中,我需要在DataGridView/ListView中显示所有数据,以便我可以查看它,如果需要,请选择并进行更改。在DataGridView/ListView上显示对象列表
但是,当我在表单上完成它时,没有任何工作,或者它只会在顶部显示构造函数名称,但不会填充任何数据。我用尽了所有选项,搜索了左右和中心,似乎没有任何方法可行。试过像DataSource = <“class”>。theList。即使尝试过DataBindings等,但似乎没有任何工作。它给人一种错误,如的<“类”>的thelist不能等的方法
在堆栈溢出的大人们呼唤,以帮助我在正确的方向上使用。谢谢大家!
编辑 我已经粘贴了一些示例代码,有关它的任何问题请求离开。谢谢你们。
public class Form{
private void form_Load()
{
Wrapper wrap = new Wrapper();
List<Child> tempList = new List<Child>();
tempList = wrap.cList;
dataGridView1.DataSource = tempList;
}
}
class Wrapper{
public List<Child> cList = new List<Child>();
public void LoadPerson()
{
string filePath = @"filepath";
//StreamReader
//code to Add each different person + their details into the
protected fields
//stores in cList variables which are in Adult
}
}
class Adult{
protected string username, firstName;
protected int number;
}
class Child: Adult{
public Child(string Username, string Password, int Number)
{
username = Username;
password = Password;
number = Number;
}
//public getters/setters next
}
请帮助我们提供代码,这些代码是您迄今为止尝试使用以获得更多理解的代码。 – mmushtaq
已编辑代码 – afx31
'DataGridView.DataSource = listOfChilds;' - 应该工作。 'Child'类是否具有您想要在datagridview中查看/编辑的字段的属性? – Fabio