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

  • SEARCH
  • Home
  • 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 8746827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:15:21+00:00 2026-06-13T12:15:21+00:00

I made an application that displays some data in a DataGridView control. The data

  • 0

I made an application that displays some data in a DataGridView control. The data is stored in an SQL database. Since there are a lot of parameters for this specific display, I created another (child) form in the same project that helps the user to add or alternate the data in the database. Both adding and alternating functions work fine, but the data in the DataGridView stays unchanged. I know how to refresh the DataGridView’s DataSource, but I don’t know how to trigger that function form another form.

I use this function to refresh the DataGridView’s DataSource:

private void RefreshMyDGV()
{
    command.CommandText = "SELECT * FROM MyDataBase";
    SDA.SelectCommand = command;
    SDA.Fill(myDataTable);
    dataGridView1.DataSource = MyDataTable;
}

I tried to change this function into a public static function so I would be able to access it from the other (child) form, but then the compiler throws errors “An object reference is required for the non-static field, method, or property”.

I also tried to define the DataGridView as public, and then access it from the other form:

((Form1)fr1).dataGridView1.DataSource = myDataTable;

But that didn’t work either.

Please suggest a way to do this.
Thanks.

  • 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-06-13T12:15:22+00:00Added an answer on June 13, 2026 at 12:15 pm

    The issue is that you are making the function static. You don’t need to do that – just make it public.

    See this documentation on the difference between static and instance methods:
    http://msdn.microsoft.com/en-us/library/aa645629(v=vs.71).aspx

    In order to call a public function, you will need a reference to the parent form instance (not just the class) from your child form. Add a property to your child form called LogicalParent of type ParentForm (substitute your actual parent form’s type) (there’s already properties named Parent and ParentForm, but they’re used for something else and you should not use them):

    public ParentForm LogicalParent{ get; set; }
    

    Now, on the parent form, when you open a new instance of the child form, set this property just before calling the Show function:

    ChildForm l_childForm = new ChildForm();
    l_childForm.LogicalParent = this;
    l_childForm.Show();
    

    Now, on the child form, you have a reference to the parent. You can now call public functions:

    this.LogicalParent.RefreshMyDGV();
    

    Alternative:

    On the parent form, pass a reference to the parent form to the ShowDialog function:

    ChildForm l_childForm = new ChildForm();
    l_childForm.ShowDialog(this);
    

    Now, on the child window, you can access the parent form via the Owner property. But you will need to cast the Owner property to you parent form’s type. So, in the child form:

    ((ParentForm)this.Owner).RefreshMyDGV();
    

    MDI:

    If you are using an MDI environment (ignore this if you don’t know what that is), then you can use the ParentForm property in the same way that you used the Owner property above (you will need to cast it to the parent’s type). MDI environment are more complicated to explain, and since you haven’t said that’s what you are using I won’t explain it here. If you need more information, visit: http://msdn.microsoft.com/en-us/library/xyhh2e7e.aspx

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

Sidebar

Related Questions

In my application, I have a control that displays the contents of a database
I made a simple application that adds 1 to the count and displays the
I have made a java application that stores data from a .csv file to
I made an application that passes trough an XML file and extracts the entries
I have made an application that gives the user the option to open up
I've made an application that makes full use of ajax, and what I need
I made a SmartDevice application that runs on startup and I want it to
I have made a web application that uses master page for Login & Logout
I have made an application in android that lets the user compress and decompress
I've been developing an application that handles accounts and transactions made over these accounts.

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.