What happens here is when in the form opens, it shows the contextMenu and display the DataGridView on it with the value of dataSet1. But when I click the button to change th
It took me a while, but I found it. Controls in a ToolStripControlHost
don't seem to get assigned the BindingContext
carried through a regular control tree.
You can take care of this yourself by adding the following to the first line of your SetDataSource
method:
dataGridView1.BindingContext = this.BindingContext;
For fair attribution, I got the idea from this web page, where a similar situation was encountered with respect to a ComboBox. I tested it out in a sample app with your code to verify it works.
Just changing the datasource of a control does not tell it to re-bind(refresh) its data from that new datasource. You need to execute the control's DataBind() command after you change its datasource.
So after this:
dataGridView1.DataSource = ds;
try adding this:
dataGridView1.DataBind();