When you update DataGridView.DataSource using the assignment operator, the DataSourceChanged event handler is called. You can’t overload assignment op in C#, so how does the event handler get called internally?
public void foo(){
this.dataGridView.DataSourceChanged += new EventHandler(bar);
this.dataGridView.DataSource = dt;
}
//this handler is called after datasource changes
private void bar(object sender, EventArgs e) {}
DataSourceis implemented as a property.A read/write property is a set of two methods, which are automatically called, when you access the property;
setwhen you assign a value,getwhen you read the property.Note also, that a change is only registered if you assign a data source something different. This means that you cannot refresh the grid by re-assigning the same data source.
Workaround: