Hi,
I'm trying to figure out how data binding with BindingSource
is supposed to work
I want a DataGridView
to be populated with the content of a List<>
upon update of the list.
I can see the List
grow and verify it's being filled when I check the debugger. I thought the BindingSource
would fire an event when the List
is changed. But none of the available is fired. How do I become notified when the underlying list is changed?
I follow the instructions and have the following test code:
Data d;
BindingSource bs;
public Form1()
{
InitializeComponent();
bs = new BindingSource();
d = new Data();
}
private void Form1_Load(object sender, EventArgs e)
{
bs.DataSourceChanged += new EventHandler(bs_DataSourceChanged);
bs.ListChanged += new ListChangedEventHandler(bs_ListChanged);
bs.DataMemberChanged += new EventHandler(bs_DataMemberChanged);
bs.CurrentChanged += new EventHandler(bs_CurrentChanged);
bs.CurrentItemChanged += new EventHandler(bs_CurrentItemChanged);
bs.DataSource = d.list;
dataGridView1.DataSource = bs;
}
// ... all the handling methods caught with a break point in VS.
private void button1_Click(object sender, EventArgs e)
{
d.addOneItem();
}