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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:46:46+00:00 2026-05-27T02:46:46+00:00

ok here we go last part almost done! one error to go hmmmmm. This

  • 0

ok here we go last part almost done! one error to go hmmmmm.
This is using the suggestion and is complaining about delegates i think.

using System;


    public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        pictureBox2.Visible = false;    
    }

    private void button1_Click(object sender, EventArgs e)
    {

        Task t = new Task(() => GetsalesFigures(accCollection.Text));

        t.Start();  
    }

    private void SetPictureBoxVisibility(bool IsVisible)
    {
        if (pictureBox2.InvokeRequired)
        {
            pictureBox2.Invoke(new Action<bool>(SetPictureBoxVisibility), new Object[] { IsVisible });
        }
        else
        {
            pictureBox2.Visible = IsVisible;
        }
    }

    private void SetCheckBoxValue(bool IsChecked)
    {
        if (checkBox1.InvokeRequired)
        {
            pictureBox2.Invoke(new Action<bool>(SetCheckBoxValue), new Object[] { IsChecked });
        }
        else
        {
            checkBox1.Checked = IsChecked;
        }
    }

    private void AddItem(string value)
    {
        if (accCollection.InvokeRequired)
        {
            accCollection.Invoke(new Action<string>(AddItem), new Object[] { value });
        }
        else
        {
            accCollection.Items.Add(value);
        }
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        AutofillAccounts();
    }


    private void GetsalesFigures(string Acct)
    {
        try
        {
            string myConn = "Server=af" +
                            "Database=sdfta;" +
                            "uid=busdf4;" +
                            "pwd=drsdft;" +
                            "Connect Tisdf=120;";

            string acct;// test using 1560
            SqlConnection conn = new SqlConnection(myConn);
            SqlCommand Pareto = new SqlCommand();
            BindingSource bindme = new BindingSource();
            SqlDataAdapter adapt1 = new SqlDataAdapter(Pareto);
            DataSet dataSet1 = new DataSet();
            DataTable table1 = new DataTable();

           //CREATE THE THREAD

            //acct = accCollection.Text;
            acct = Acct;

            string fromDate = this.dateTimePicker1.Value.ToString("MM/dd/yyyy");
            string tooDate = this.dateTimePicker2.Value.ToString("MM/dd/yyyy");

            Pareto.Connection = conn;
            Pareto.CommandType = CommandType.StoredProcedure;
            Pareto.CommandText = "dbo.GetSalesParetotemp";
            Pareto.CommandTimeout = 120;

            Pareto.Parameters.AddWithValue("@acct", acct);
            Pareto.Parameters.AddWithValue("@from", fromDate);
            Pareto.Parameters.AddWithValue("@too", tooDate);


            //pictureBox2.Visible = true;
            //checkBox1.Checked = true;
            SetCheckBoxValue(true);
            SetPictureBoxVisibility(true);

            adapt1.Fill(dataSet1, "Pareto");
            //checkBox1.Checked = false;
            //pictureBox2.Visible = false;
            SetCheckBoxValue(false);
            SetPictureBoxVisibility(true);

            this.dataGridView1.AutoGenerateColumns = true;
            this.dataGridView1.DataSource = dataSet1;
            this.dataGridView1.DataMember = "Pareto";

            dataGridView1.AutoResizeColumns(
                DataGridViewAutoSizeColumnsMode.AllCells);

            SetPictureBoxVisibility(true);
            acct = Acct;

        }
        catch (Exception execc)
        {
            MessageBox.Show("Whoops! Seems we couldnt connect to the server!"
                            + " information:\n\n" + execc.Message + execc.StackTrace,
                            "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
        } 
    }

    private void AutofillAccounts()
    {
        //get customers list and fill combo box on form load.
        try
        {
            string myConn1 = "Server=sdf33;" +
                                "Database=sdft;" +
                                "uid=bdf4;" +
                                "pwd=ddft;" +
                                "Connect Timeout=6000;";
            SqlConnection conn1 = new SqlConnection(myConn1);
            conn1.Open();
            SqlCommand accountFill = new SqlCommand("SELECT keycode FROM dbo.Customer", conn1);

            SqlDataReader readacc = accountFill.ExecuteReader();

            while (readacc.Read())
            {
                AddItem(readacc.GetString(0).ToString());
            }
            conn1.Close();
        }
        catch(Exception exc1)
        {
            MessageBox.Show("Whoops! Seems we couldnt connect to the server!"
                            + " information:\n\n" + exc1.Message + exc1.StackTrace,
                            "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
        }
    }
}

}

not sure where the changes should be made, shouldnt it be in the account method now?

  • 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-27T02:46:47+00:00Added an answer on May 27, 2026 at 2:46 am

    Fixed some minor spelling errors, didn’t have a compiler at hand back then.
    To your last error: Just provide the accCollection.Text as parameter to your method. See the updated button1_Click() and GetsalesFigures(String Acct).
    This is how my Partial Class : Form looks like

      public Form1()
    {
      InitializeComponent();
      pictureBox2.Visible = false;
    }
    private void Form1_Load(object sender, EventArgs e) 
    { 
      AutofillAccounts(); 
    }  
    private void button1_Click(object sender, EventArgs e)
    {
      checkBox1.Checked = true;
      string acct = accCollection.Text;
      Task t = new Task(() => GetsalesFigures(acct)); 
      t.Start();
    }
    private void GetsalesFigures(String Acct)
    {
      // (...)
      //pictureBox2.Visible = true; use SetPictureBoxVisibility
      SetPictureBoxVisibility(true);
      //checkBox1.Checked = true; use SetCheckBoxValue
      SetCheckBoxValue(true);
      // (...)
      SetCheckBoxValue(false);
      SetPictureBoxVisibility(false); 
      // (...)
      acct = Acct;
     // (...)
     SetDataGrid(true, dataSet1, "Pareto", DataGridViewAutoSizeColumnsMode.AllCells);
    }
    private void AutofillAccounts()
    {
       // (...)
       while (readacc.Read())             
        {                 
          AddItem(readacc.GetString(0).ToString());             
        }
    }
    private void SetCheckBoxValue(bool IsChecked)
    {
      if (checkBox1.InvokeRequired)
      {
        pictureBox2.Invoke(new Action<bool>(SetCheckBoxValue), new Object[] { IsChecked });
      }
      else
      {
        checkBox1.Checked = IsChecked;
      }
    }
    private void SetPictureBoxVisibility(bool IsVisible)
    {
      if (pictureBox2.InvokeRequired)
      {
        pictureBox2.Invoke(new Action<bool>(SetPictureBoxVisibility), new Object[] { IsVisible });
      }
      else
      {
        pictureBox2.Visible = IsVisible;
      }
    }
    // Your latest comment
     private void AddItem(string value)
     {
      if (accCollection.InvokeRequired)
      {
        accCollection.Invoke(new Action<string>(AddItem), new Object[] {   value });
      }
      else
      {
        accCollection.Items.Add(value);
      }
    }
    private void SetDataGrid(bool AutoGenerateColumns, Object DataSource, String DataMember, DataGridViewAutoSizeColumnsMode Mode)
    {
      if (this.dataGridView1.InvokeRequired)
      {
        this.dataGridView1.Invoke(new Action<bool, Object, String,   DataGridViewAutoSizeColumnsMode>(SetDataGrid),
                                  AutoGenerateColumns, DataSource, DataMember, Mode);
      }
      else
      {
        this.dataGridView1.AutoGenerateColumns = AutoGenerateColumns;
        this.dataGridView1.DataSource = DataSource;
        this.dataGridView1.DataMember = DataMember;
        dataGridView1.AutoResizeColumns(Mode);
      }
    }
    

    And Program.cs

     static class Program
    {
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
      Application.EnableVisualStyles();
      Application.SetCompatibleTextRenderingDefault(false);
      Application.Run(new Form1());
    }
    

    To summary your problem: You have to encapsulate all control-related updates you want to call from another thread than the main thread just like I did it with the two controls.

    Some ressources you might want to check for multithreading / tasks
    http://msdn.microsoft.com/en-us/library/system.threading.tasks.task.aspx
    http://blogs.msdn.com/b/pfxteam/archive/2009/06/30/9809774.aspx

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

Sidebar

Related Questions

I am stuck here and i spend last 2 days resolving this issue but
I was wondering about the last constructor for std::string mentioned here . It says:
Hopefully the last NN question you'll get from me this weekend, but here goes
I'm using some code from here to determine when determining when the last finger
With reference to the last part of answer given here: What's the difference between
Here is my last login part that dosen't seem to work here it is.
Here is my problem. I'd like to get the last inserted Id with a
After my last, failed, attempt at asking a question here I'm trying a more
How do you get the last day of the last month in csh? Here
I have an interesting problem here I've been trying to solve for the last

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.