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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:20:23+00:00 2026-06-14T21:20:23+00:00

When i load the file into the datagrid, i’m getting a error message, FormatException

  • 0

When i load the file into the datagrid, i’m getting a error message, FormatException Error.
Here, what i’m trying to do, comparing the two cell vlaues, if the col index 2 value is greater than col index 3, then show a error message.

When iload the file for the first time, i have no issues. I fi load for the seconfd time, i'm gettign the above error message.

I tried using Convert.ToInt32, int, still i’m getting the same error message. How can i fix this??

private void datagridview_CellValidating(object sender, CellValidatingEventArgs e)
{
if (e.ColumnIndex != 0)
{
    if (e.RowIndex >= 0 && e.RowIndex < 8)
    {
        if (e.Value != null && datagridview.Rows[e.RowIndex].Cells[e.ColumnIndex - 1].Value != null)
        {
                //Convert.ToInt32, int////
            if (Double.Parse(e.Value.ToString()) <=
                Double.Parse(datagridview.Rows[e.RowIndex].Cells[e.ColumnIndex - 1].Value.ToString()))
            {
                MessageBox.Show("error");
                e.Cancel = true;
                datagridview.Rows[e.RowIndex].ErrorText = errorMesssage;
            }
        }
    }
}
}
  • 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-14T21:20:24+00:00Added an answer on June 14, 2026 at 9:20 pm

    I think you should revisit your condition here

    if (Double.Parse(e.Value.ToString()) <=    
        Double.Parse(datagridview.Rows[e.RowIndex].Cells[e.ColumnIndex - 1].Value.ToString()))
    

    Now what would happen when you are validating for Column1 the comparison would be with the value available in Column2 and Column1 (not as what you mentioned), so if the Value in Column1 cannot be parsed then it would pop up a format exception since it cannot be parsed.

    So maybe you need to specify the columns in your if clause

    if (e.ColumnIndex != 0) // here you allow for Column3, so that e.ColumnIndex - 1 is 2

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

Sidebar

Related Questions

I'm trying to load a file into a string. Here is the code I'm
I have problems trying to load png file into my application. It seems to
I am trying to figure out an eazy way to load CSV file into
I am trying to achieve a situation where i load a file into the
I was trying to load a data file into mysql table using LOAD DATA
I want to do two things in my browser: Load a text file into
WinRT project, C++/CX. I'm trying to load a PNG file into a WriteableBitmap. I'm
Trying to load a file into python. It's a very big file (1.5Gb), but
I am trying to load a file into IRB. I have the file saved
We are trying to load a file created by fast export into an oracle

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.