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

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

The Archive Base Latest Questions

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

I have a DatGridView to which I add new rows. The first column of

  • 0

I have a DatGridView to which I add new rows. The first column of every row is an image the indicates whether the rest of the row has been completed. To keep track of this each row has a List-like object attached to it that counts the number of completed fields, then changes the image if enough fields have been completed. This works exactly as expected when the user is adding rows in the GUI, however I run into problems when I try to add new rows programmatically.

When a new row is created, the DataGridViewImageCell from the first column is added to the custom class that keeps track of the completed fields.

Here is the code to add a new row:

//initiate the new row
object[] buffer = new object[13];
buffer[0] = nullImage; //a blank image

for (int i = 1; i < buffer.Length; i++)
{
     buffer[i] = String.Empty;
}

rowID = DataGridView1.Rows.Add(buffer);

Here is the RowAdded code:

    private void DataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
    {
        DataGridViewImageCell tmp = (DataGridViewImageCell)DataGridView1.Rows[DataGridView1.RowCount - 1].Cells[0];
        DataGridView1ValidateFields.AddRow(tmp); //custom class to keep track of completed fields
    }

The custom class contains a List of DataGridViewImageCells dgvic; here is its’ AddRow method:

    private List<object> dgvic = new List<object>();
    public void AddRow(DataGridViewImageCell p)
    {
        items.Add(new List<int>());//List of ints to keep track of completed fields
        dgvic.Add(p);
    }

When I enter the debugger (while adding rows programmatically) I can see that each time I add a new row the DataGridViewImageCells stored in dgvic are all from the most recent row. For instance after adding 3 rows, I’d expect the 3 DataGridViewImageCells to be from rows 0, 1 and 2; however all of them are from row 2.

It looks to me that RowCount is still tied to each DataGridViewCell, and as RowCount increments the cell changes. If this were the case though, how come it works through the GUI? Does anyone have any ideas?

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

    Change yours AddedRows event as follows:

    private void DataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
    {
        int index = e.RowIndex;
        for (int i = 0; i < e.RowCount; i++)
        {
            DataGridViewImageCell tmp = (DataGridViewImageCell)DataGridView1.Rows[index].Cells[0];
            DataGridView1ValidateFields.AddRow(tmp);
            index++;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DataGridView which has different rows and columns and it work perfectly
I have a DataGridView which allows the user to add a new object to
i have 6 column in which the first column is a textboxcell and the
I have a dataGrid(not dataGridView) in which i need to add Checkbox dynamically at
I have a datagridview in which one column contains a custom class, which I
I have a datagridview column 'total',in which I am doing sum of rates of
I have a datagridview with a bound combobox column which contains decimal value. There
I have a DataGridView with a DataGridViewComboBoxColumn in the first column that is bind
i have a winform datagridview: DataTable table = new DataTable(); table.Columns.Add(Check, typeof(bool)); table.Columns.Add(User, typeof(string));
I have a .NET windows app. I have a DataGridView which has a few

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.