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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:40:52+00:00 2026-06-06T18:40:52+00:00

There is a backround worker, a tableLayoutPanel, and a bunch of gridviews and labels

  • 0

There is a backround worker, a tableLayoutPanel, and a bunch of gridviews and labels that I add (dynamically – programmaticaly) to the tablelayoutpanel.

The above code works fine, but I need to add an onclick event on the row that will be added to the gridview each time. How can I do this?

 var lbltotalcount = tableLayoutPanel1.Controls.Find("lbltotalcount_" + GridId, true);
            ((Label)lbltotalcount[0]).Invoke((MethodInvoker)delegate
            {
                ((Label)lbltotalcount[0]).Text = (Convert.ToInt32(((Label)lbltotalcount[0]).Text) + NumOfMatch).ToString();
            });    

            var obj = tableLayoutPanel1.Controls.Find("dgv_" + GridId, true);


            ((DataGridView)obj[0]).Invoke((MethodInvoker)delegate
            {
                string[] row = new string[] { Word, txturl.Text, Url, NumOfMatch.ToString() };

                DataGridViewRow dgvRow = new DataGridViewRow();
                DataGridViewCell dgvCell;

                dgvCell = new DataGridViewTextBoxCell();                
                dgvCell.Value = Word;
                dgvRow.Cells.Add(dgvCell);                

                dgvCell = new DataGridViewTextBoxCell();
                dgvCell.Value = txturl.Text;
                dgvRow.Cells.Add(dgvCell);

                dgvCell = new DataGridViewTextBoxCell();
                dgvCell.Value = Url;
                dgvRow.Cells.Add(dgvCell);

                dgvCell = new DataGridViewTextBoxCell();
                dgvCell.Value = NumOfMatch.ToString();
                dgvRow.Cells.Add(dgvCell);                                              

                ((DataGridView)obj[0]).Rows.Add(dgvRow);
                ((DataGridView)obj[0]).Refresh();
                ((DataGridView)obj[0]).Update();
            });                    
  • 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-06T18:40:53+00:00Added an answer on June 6, 2026 at 6:40 pm

    I am not sure that is what you want.. lets try it..

      void yourMethod()
     {
      var lbltotalcount = tableLayoutPanel1.Controls.Find("lbltotalcount_" + GridId, true);
              ((Label)lbltotalcount[0]).Invoke((MethodInvoker)delegate
            {
                ((Label)lbltotalcount[0]).Text =     (Convert.ToInt32(((Label)lbltotalcount[0]).Text) + NumOfMatch).ToString();
            });    
    
            var obj = tableLayoutPanel1.Controls.Find("dgv_" + GridId, true);
    
           ((DataGridView)obj[0]).SelectionChanged += new EventHandler(My_SelectionChanged);
    
    
            ((DataGridView)obj[0]).Invoke((MethodInvoker)delegate
            {
                string[] row = new string[] { Word, txturl.Text, Url, NumOfMatch.ToString() };
    
                DataGridViewRow dgvRow = new DataGridViewRow();
                DataGridViewCell dgvCell;
    
                dgvCell = new DataGridViewTextBoxCell();                
                dgvCell.Value = Word;
                dgvRow.Cells.Add(dgvCell);                
    
                dgvCell = new DataGridViewTextBoxCell();
                dgvCell.Value = txturl.Text;
                dgvRow.Cells.Add(dgvCell);
    
                dgvCell = new DataGridViewTextBoxCell();
                dgvCell.Value = Url;
                dgvRow.Cells.Add(dgvCell);
    
                dgvCell = new DataGridViewTextBoxCell();
                dgvCell.Value = NumOfMatch.ToString();
                dgvRow.Cells.Add(dgvCell);                                              
    
                ((DataGridView)obj[0]).Rows.Add(dgvRow);
                ((DataGridView)obj[0]).Refresh();
                ((DataGridView)obj[0]).Update();
              var index = ((DataGridView) obj[0]).RowCount;
              ((DataGridView) obj[0]).SelectedRows[index - 1].Selected = true;
            });  
      }
    
       void My_SelectionChanged(object sender, EventArgs e)
        {
          // bla bla ...
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that can spawn background worker threads from anywhere within it.
in code behind we set the imagepath of window background ,is there any way
I am running a background worker thread that takes a long time to run.
I have an application that uses background workers. There are places that a background
Is there a way to directly restart a background worker? Calling CancelAsync() followed by
I have a WPF application with two background worker threads that operate while loading.
What happens to the data that is passed to and from a background worker?
While maintaining some code, I discovered that we have an infinite hang-up in a
I have a django project that uses a worker process that sends emails to
I have a background worker process that starts provisioning a new client for our

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.