I have a List
and a DataGridView
. I added elements to the List
, but when I tried to show that List
value in the DataGridView
, it's not shown.
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;
private void btnDataGridView_Click(object sender, EventArgs e){
var source = new BindingSource();
source.Datasource = lst;
LinqdataGridView.DataSource = source;
}
Hope helps,
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.