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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:37:05+00:00 2026-06-14T18:37:05+00:00

until yesterday the below code was workig fine but today I’m getting a error

  • 0

until yesterday the below code was workig fine but today I’m getting a error message Argument out of exception & index out of range.

Wha t i’m tryring to do here, from the index 3(4th col) of the last row, take that cell value & put in to the col 3 (index 2) cell. When i type it in the last cell (from bottom to top), i’m getting the above error message.

Please help me.

private void datagridview_CellValidated(object sender, CellValidatedEventArgs e)
{

if (e.ColumnIndex != 3)
    return;
int nextRowIndex = e.RowIndex -1;
int lastRowIndex = datagridview.Rows.Count;
try
{

        if (nextRowIndex <= lastRowIndex)
        {
            var valuesForcell = datagridview.Rows[e.RowIndex].Cells[3].Value.ToString();
            datagridview.Rows[nextRowIndex].Cells[2].Value = valuesForcell;
            datagridview.Rows[nextRowIndex].Cells[2].ReadOnly = true;
            datagridview.Rows[nextRowIndex].Cells[2].Style.ForeColor = Color.MediumVioletRed;
            datagridview.ClearSelection();
            datagridview.SelectionMode = GridViewSelectionMode.CellSelect;
            datagridview.Rows[nextRowIndex].Cells[3].BeginEdit();

        }

}
catch (Exception exception) { }


}

enter image description here
enter image description here

  • 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-14T18:37:07+00:00Added an answer on June 14, 2026 at 6:37 pm

    if I understand well you should have:

    private void datagridview_CellValidated(object sender, CellValidatedEventArgs e)
    {
    
    if (e.ColumnIndex != 3)
        return;
    int nextRowIndex = e.RowIndex -1;
    try
    {
    
            if (nextRowIndex >=0 )
            {
                var valuesForcell = datagridview.Rows[e.RowIndex].Cells[3].Value.ToString();
                datagridview.Rows[nextRowIndex].Cells[2].Value = valuesForcell;
                datagridview.Rows[nextRowIndex].Cells[2].ReadOnly = true;
                datagridview.Rows[nextRowIndex].Cells[2].Style.ForeColor = Color.MediumVioletRed;
                datagridview.ClearSelection();
                datagridview.SelectionMode = GridViewSelectionMode.CellSelect;
                datagridview.Rows[nextRowIndex].Cells[3].BeginEdit();
    
            }
    
    }
    catch (Exception exception) { }
    
    
    } 
    

    You are moving values bottom-up right?

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

Sidebar

Related Questions

Until yesterday everything was normal but today i try to lauch my application using
Until yesterday everything was fine to my localhost, but starting yesterday, localhost is not
I'm requesting the installed drive apps. This worked fine until yesterday. Today I get:
I'm sure my app worked right until yesterday, when I got this error: Failed
i have a Magento site in which the checkout process worked fine until yesterday
Yesterday Tomcat was running ok, but today when I try to run my web-app
Up until yesterday jQuery was loading just fine in my Rails app. I was
I have wordpress installation on my root folder, until yesterday it was working fine,
I have a master-master MySQL replication. It was delicious until yesterday but, for some
My code which was working until yesterday, all of a sudden has started throwing

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.