In the Winforms project, try this code (the simulator view of what you posted, and it works !), and then match / debug your existing code to narrow down the problem: -
DataGridView dgv = new DataGridView();
//Note: AutogenerateColumns is true by default
BindingSource bs = new BindingSource();
BindingList<Customer> bList = new BindingList<Customer>();
// Fill bList with Customers
bList.Add(new Customer(){Name="John"});
bs.DataSource = bList;
dgv.DataSource = bs;
this.Controls.Add(dgv);
MyObject equivalent : -
public class Customer
{
public string Name { get; set; }
}
So, to Debug your codeby matching with the above, you can remove these bits -
this.bindingSource1.SuspendBinding();
this.dataGridView1.Columns.Clear();
this.dataGridView1.AutoGenerateColumns = true;
this.dataGridView1.Enabled = false;
this.dataGridView1.Invalidate();
this.bindingSource1.ResumeBinding();
this.dataGridView1.Enabled = true;
this.dataGridView1.Refresh();
& just have thisin the first test -
this.bindingSource1.DataSource = bList;
this.dataGridView1.DataSource = bindingSource1;
source
share