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 9242287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:33:02+00:00 2026-06-18T08:33:02+00:00

Updated to be more clear…. I have a main form, Form1 , and an

  • 0

Updated to be more clear….

I have a main form, Form1, and an additional class, AslLib. Form1 contains a method that updates a dataGridView control it contains. A method in AslLib calls this method.

My problem is that the only way I can make AslLib call Form1‘s method is by creating an instance of Form1 in AslLib‘s calling method like so:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    public void updateDataGUI(int row, string url, string status, long time)
    {
        Console.WriteLine(status);
        foreach (DataGridViewRow dgvr in dataGridView1.Rows) dgvr.Cells[0].Value = status;
    }

}



static class AslLib
{
    public static async void makeRequest(string url, int row )
    {
        string result;
        Stopwatch sw = new Stopwatch(); sw.Start();

        try
        {
            using (HttpClient client = new HttpClient())
            {
                HttpResponseMessage response = new HttpResponseMessage();
                response = await client.GetAsync(url);

                if (response.IsSuccessStatusCode)
                {
                    result = ((int)response.StatusCode).ToString();
                }
                else
                {
                    result = ((int)response.StatusCode).ToString();
                }
            }
        }
        catch (HttpRequestException hre)
        {
            result = "Server unreachable";
        }

        sw.Stop();
        long time = sw.ElapsedTicks / (Stopwatch.Frequency / (1000L * 1000L));


        _form.updateDataGUI(row, url, result, time);

    }
}

I have tried passing parameters in both the constructor and the method, but because (i think) the makeRequest method is static, the compiler is giving errors:

AsyncURLChecker.AslLib._form: cannot declare instance members in a static class              AsyncURLChecker
Static classes cannot have instance constructors                AsyncURLChecker

The result of the above is that the Console.WriteLine(status); part of Form1‘s method correctly outputs status, but the dataGridView does not change.

My belief is that because I am creating a new instance of Form1, I am no longer referencing the original Form1 containing my dataGridView, rather an entirely new copy, so it is not changing.

Can anyone tell me how I might manipulate the original Form1’s dataGridView from another class? My preferred method would be to call a Form1 method that updates dataGridView rather than directly accessing dataGridGiew from AslLib if possible.

  • 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-18T08:33:03+00:00Added an answer on June 18, 2026 at 8:33 am

    You should pass reference to existing form instead of creating new one:

    // on Form1
    Class1 c1 = new Class1();
    c1.DoSomething(this);
    
    // Class1
    public void DoSomething(Form1 form)
    {
        form.updateDataGUI(row, url, result, time);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

UPDATED, TO BE MORE CLEAR: My current field that contains the value ‘1201026404’ (which
Updated in an attempt to be more clear I have three list of dictionaries
Updated question to make it more clear I understand that you can set the
Updated the question in order to make it more clear: I'm interacting with an
This is a running question that I have updated to hopefully be a little
I have a class that implements IValidateObject. My business rule is satisfied after I
UPDATE: I've been playing around with this more, and it seems like tmux's clear-history
UPDATED: Added one more question (Question #4). Hi all, I'm building myself a custom
[Updated with partial answers, some more detailed questions.] Does CouchDB support multi-domain hosting? Yes,
Code is read more often then updated. Writing more readable code is better than

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.