[英]Show List value in DataGridView
I have a List
and a DataGridView
. 我有一个List
和一个DataGridView
。 I added elements to the List
, but when I tried to show that List
value in the DataGridView
, it's not shown. 我向List
添加了元素,但是当我试图在DataGridView
显示List
值时,它没有显示。
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;
}
}
You can use BindingSource
, try this; 您可以使用BindingSource
,尝试一下;
private void btnDataGridView_Click(object sender, EventArgs e){
var source = new BindingSource();
source.Datasource = lst;
LinqdataGridView.DataSource = source;
}
Hope helps, 希望有帮助,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.