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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:08:25+00:00 2026-06-13T11:08:25+00:00

I got 2 Datagridview in my form and I’m using cell validation and cell

  • 0

I got 2 Datagridview in my form and I’m using cell validation and cell validating event handler.. in my datagridview. If i leave the cursor in the cell itself and try to open a new file through menu click..i’m getting a error message : “Argument out of exception was unhandled by usercode, index was out of range.”

I know, when the cursor is in the cell, it got focus and it’s in the process of cell validating that’s why i’m getting this error.

This line throws the error with the message : “Argument out of exception was unhandled by usercode, index was out of range.”
datagridview.Rows[e.RowIndex].ErrorText = "";

How can i avoid this error?? Or How can i remove focus during menu click to open a new file?? Thank you.

private void datagridview_CellValidating(object sender, CellValidatingEventArgs e)
            {
                if (e.ColumnInfo.Name == "Item1" || e.ColumnInfo.Name == "Item2")
                {
                    datagridview.Rows[e.RowIndex].ErrorText = "";
                    int newInteger;
                    if (datagridview.Rows[e.RowIndex].IsModified)
                        return;
                    if (!int.TryParse(e.Value.ToString(),
                         out newInteger) || newInteger < -50000 || newInteger > 50000)
                    {
                        e.Cancel = true;
                        datagridview.Rows[e.RowIndex].ErrorText = "The value must be a non-negative integer";
                    }
                }

            }

 private void datagridview_CellValidated(object sender, CellValidatedEventArgs e)
            {

                if (e.ColumnIndex != 3)
                    return;
                int nextRowIndex = e.RowIndex + 1;
                int lastRowIndex = datagridview.Rows.Count - 1;
                if (nextRowIndex <= lastRowIndex)
                {
                    var value = datagridview.Rows[e.RowIndex].Cells[3].Value.ToString();
                    datagridview.Rows[nextRowIndex].Cells[2].Value = value;
                }
            }

MenuItem Clik to open new files to the Datagridview:

private void m_test1_Click_1(object sender, EventArgs e)
    {
        myconfig = Myconfig.DeserializeFromXmlFile(@"test2.xml");
        Display(rseConfig);
        m_ConfigPages.Visible = true;

    }



private void m_test2_Click(object sender, EventArgs e)
  {
        myconfig = Myconfig.DeserializeFromXmlFile(@"test2.xml");
        Display(myconfig );
        m_ConfigPages.Visible = true;

    }

I’m using DataError Event Hnadler, but it’s not working:

private void datagridview_DataError(object sender, DataGridViewDataErrorEventArgs e)
        {
            // Don't throw an exception when we're done.
            e.ThrowException = false;

            // Display an error message.
            string txt = "Error with " +
                datagridview.Columns[e.ColumnIndex].HeaderText +
                "\n\n" + e.Exception.Message;
            MessageBox.Show(txt, "Error",
                MessageBoxButtons.OK, MessageBoxIcon.Error);

            // If this is true, then the user is trapped in this cell.
            e.Cancel = true;
        }

Even, i have with row and col index : datagridview.Rows[e.RowIndex].Cells[e.ColumnIndex].Value still not working.

  • 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-13T11:08:26+00:00Added an answer on June 13, 2026 at 11:08 am

    Try to add this event

    dgv.DataError += new DataGridViewDataErrorEventHandler(dgv_DataError);
    
    
    void dgv_DataError(object sender, DataGridViewDataErrorEventArgs e)
    {
          //Show any message or not.. its upto you now 
    }
    

    Edit :

    Modify your cellvalidating event as

    private void datagridview_CellValidating(object sender, CellValidatingEventArgs e)
    {
      try
      {
         int temp = Convert.ToInt32(e.Value.ToString())
         if(temp < -5000 || temp > 5000)     
              datagridview.Rows[e.RowIndex].ErrorText = "The value must be bteewn 5000 and 5000";
      }
      catch
      {
         datagridview.Rows[e.RowIndex].ErrorText = "The value must be integer and bteewn 5000 and 5000";
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a simple form with a DataGridView element on it. In the constructor
I've got a Windows Form with a button and a datagridview. The project includes
I've got a combobox that opens a new form window with a datagridview, and
i've got an event handler for columncontentclicked and it works fine, until i shorten
I've got a DataGridView in a vb.net form, not connected to any source. I
I've got a DataGridView in a modal window with a list of options for
I've got a DataGridView control, which is to hold around 100,000 records. It's currently
I've got some Columns in a DataGridView that have their Binding property set to
I'm creating a datagridview transparent //I got the parent background image Bitmap parentBackGround =
I've got a dynamically filled datagrid view. When a user right clicks a cell

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.