0
我试图将List设置为ComboBox的DataSource。用户属性以.txt文件格式保存:用户名;密码; isAdministrator。参考MSDN,我做了一切正确的事情。如何正确设置ComboBox数据源?
List<User> users = new List<User>();
public ComboBoxForm()
{
string path = "data\\usr.txt";
string[] rows = File.ReadAllLines(path);
for(int i = 0; i < rows.Length; i++)
{
string[] atributes = rows[i].Split(';');
User u = new User(atributes[0], atributes[1], atributes[2]);
users.Add(u);
}
comboBox1.DataSource = users;
InitializeComponent();
}
但是每次运行应用程序时,它都会与NullReferrenceException一起崩溃。我错过了什么?
你能发表您的堆栈跟踪? –