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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:59:02+00:00 2026-06-14T17:59:02+00:00

I was trying to get the row count of a DataGridView [ dataGridView1.Rows.Count ].

  • 0

I was trying to get the row count of a DataGridView [ dataGridView1.Rows.Count ]. I found out that the row count is still 0 when though the UI shows multiple rows added already in the DataGridView. I figured out that this might be a threading thinggy so I used the following code to retrieve the row count :

public void OnTagsReported( ... )
{
  ...  

  for( var i = GetDataGridViewRowCount( dgvScanResult ) - 1; i >= 0; i-- )
  {
    var row = dgvScan.Rows[ i ];
    ...
  }  
  ...
}

protected int GetDataGridViewRowCount( DataGridView gridView )
{
  try
  {
    if( ! InvokeRequired )
    {
      return gridView.Rows.Count;
    }

    var count  = 0;
    var action = new Action<DataGridView>( delegate( DataGridView c ) 
                 { count = c.Rows.Count; } );

    gridView.Invoke( action, gridView );

    return count;
  }
  catch( ObjectDisposedException ) {}
  catch( InvalidOperationException ) {}
}

I get the row count but was wondering if this is the correct way. May I know how would ya’ll do it?

Thank you all for your kind attention and opinion.

  • 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-14T17:59:03+00:00Added an answer on June 14, 2026 at 5:59 pm

    Why is your OnTagsReported method in another thread? Anyway, two comments.

    First: Yes you can do it like that, but in GetDataGridViewRowCount is an error. You should call InvokeRequired also on the gridView because you are using gridview.Invoke later on.

    Second: Better call your OnTagsReported method in the correct thread. Then you don’t need the GetDataGridViewRowCount method.

    public void OnTagsReported()
    {
      if (dgvScanResult.InvokeRequired)
      {
        dgvScanResult.Invoke(new MethodInvoker(OnTagsReported), null);
        return;
      }
    
      for( var i = dgvScanResult.Rows.Count - 1; i >= 0; i-- )
      {
        var row = dgvScan.Rows[ i ];
        ...
      }  
      ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get distinct id's out of a 6 million row table. The
I'm trying to get fastercsv setup so that rather than parsing each row, it
I'm trying to make a customized view that gets me the row count for
I'm trying to get the count of the number of rows on the current
I am trying to get row count from the following query. I get only
In SQL Server 2008, I'm trying to quickly get a row count on a
I'm trying to get an average of a distinct count per day out of
I am trying to get the row count of a result set by: rs.last();
Hi i'm trying to get a row count from a table using Watin ie
I am trying to delete multiple selected rows from a DataGridView. When I try

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.