我有List
和DataGridView
。我在List
添加了元素,但当我尝试在List
中显示DataGridView
值时,它未显示。
public partial class Queries : Form {
List<EmployeeDetails> lst = new List<EmployeeDetails> { };
public Queries() {
InitializeComponent();
}
public void btnSubmit_Click(object sender, EventArgs e) {
EmployeeDetails emp = new EmployeeDetails();
emp.id = Convert.ToInt32(numId.Value);
emp.name = tbName.Text;
emp.malecheck = rbMale.Checked;
emp.femealecheck = rbFemale.Checked;
lst.Add(emp);
}
private void btnDataGridView_Click(object sender, EventArgs e) {
LinqdataGridView.DataSource = lst;
}
}
答案 0 :(得分:0)
您可以使用BindingSource
,试试这个;
private void btnDataGridView_Click(object sender, EventArgs e){
var source = new BindingSource();
source.Datasource = lst;
LinqdataGridView.DataSource = source;
}
希望有所帮助,