Hi All,
I have a windows datagridview that I am having some issues with.
The problem is that after the grid is bound to the object datasource it does not seem to reflect changes to the base datasource.
How do I refresh the grid to show the true dataset from the object.
Below is the test code I have used to try to get this to work.
The datasource is populated in the form constructor and bound to the grid.
Button one add new data to the data source.(I thought this should be all that was needed.)
Button two is trying to rebind, but not sure what to do here.
Code:
public partial class Form1 : Form
{
People people = new People();//List of person objects
public Form1()
{
InitializeComponent();
for (int i = 0; i < 5; i++)
{
Person p = new Person();
p.FirstName = "Rod_" + i.ToString();
p.LastName = "McLeay_" + i.ToString();
people.Add(p);
}
dataGridView1.DataSource = people;
}
private void button1_Click(object sender, EventArgs e)
{
Person p = new Person();
p.FirstName = "Rod_" + people.Count.ToString();
p.LastName = "McLeay_" + people.Count.ToString();
people.Add(p);
}
private void button2_Click(object sender, EventArgs e)
{
dataGridView1.DataSource = people;
dataGridView1.Refresh();
}
}
======================================
They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================