I have a DataGridView inside a ContextMenu control, please see the code snippet below:
private void Form1_Load(object sender, EventArgs e)
{
SetDataSource(dataSet1);// A populated DataSet
}
protected void SetDataSource(DataSet ds)
{
dataGridView1.DataSource = ds;
ToolStripControlHost tsHost = new ToolStripControlHost(dataGridView1);
contextMenuStrip1.Items.Clear();
contextMenuStrip1.Items.Add(tsHost);
开发者_JS百科 contextMenuStrip1.Show(textBox1, 0, 27);
}
private void button1_Click(object sender, EventArgs e)
{
SetDataSource(dataSet2);// Another populated DataSet
}
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 the DataSource of the Grid, It doesn't show the records of dataSet2. Please help me how to fix this... thanks...
You might try setting the DGV's DataSource to a BindingSource object, and then modifying the BindingSource's DataSource instead. You can force the BindingSource to update, if it doesn't automatically, by invoking its CurrencyManager.Refresh().
精彩评论