Hi zenox,
>potentialInvestorDataGridView.DataBindings.Add("DataSource", bindingSource, "PotentialInvestors"); It is not clear to me why you use simple binding for a list and DataGridView? What you need to do is using complex binding. Please look at the following code.
public partial class Form1 : Form
{
private BindingList<Company> compList = new BindingList<Company>();
public Form1()
{
InitializeComponent();
compList.Add(new Company(1, "Microsoft"));
compList.Add(new Company(2, "Google"));
dataGridView1.DataSource = compList;
}
private void button1_Click(object sender, EventArgs e)
{
compList.Add(new Company(3, "IBM"));
}
}
public struct Company
{
private int companyID;
public int CompanyID
{
get { return companyID; }
set { companyID = value; }
}
private string companyName;
public string CompanyName
{
get { return companyName; }
set { companyName = value; }
}
public Company(int id, string name)
{
this.companyID = id;
this.companyName = name;
}
}
First I need to create a type (company type) with CompanyID and CompanyName. Then I call BindingList.Add method to add new items. You can see I set the DataSource property of DataGridView to bind it to compList.
When I click button1, I added another item into the compList, it displayed on the DataGridView immediately.
Hope this helps you. If I misunderstood you, please feel free to tell me.
Sincerely,
Kira Qian
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the
All-In-One Code Framework!