Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 992985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:21:02+00:00 2026-05-16T06:21:02+00:00

What happens here is when in the form opens, it shows the contextMenu and

  • 0

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.

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);
    contextMenuStrip1.Show(textBox1, 0, 27);
}

private void button1_Click(object sender, EventArgs e)
{
    SetDataSource(dataSet2);// Another populated DataSet
}

I tried adding another DataGridView control (dataGridView2) in my form, but this time I did not put it in a ToolStripControlHost and I did not add it to the contextMenuStrip1.

dataGridView1.DataSource = ds;
dataGridView2.DataSource = ds; // <-- Parent of this is the Form1, the control is not added in the contextMenuStrip.
ToolStripControlHost tsHost = new ToolStripControlHost(dataGridView1);
contextMenuStrip1.Items.Clear();
contextMenuStrip1.Items.Add(tsHost);
contextMenuStrip1.Show(textBox1, 0, 27);

When the Form1 loads, the contextMenuStrip1 popups and the dataGridView1 is being added as an item to it making dataGridView1 to disappear in the form and the dataGridView2 only remains in the Form1.

When I hit the button1 the dataGridView2 changes its content base from its new DataSource (dataSet2), while the dataGridView1 still displays the value of dataSet1.
What I noticed is when the time dataGridView1 is being added to the ToolStripHost, and make it an Item in the contextMenuStrip1, the DataSource property of the DataGridView control is not being changed anymore. Unlike the dataGridView2 that remains in the form which I did not add to the contextMenuStrip1.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T06:21:02+00:00Added an answer on May 16, 2026 at 6:21 am

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.