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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:44:59+00:00 2026-06-09T09:44:59+00:00

I have a strange outcome when I run this code – I have a

  • 0

I have a strange outcome when I run this code – I have a datagridview with a basic stock list (name, onHand, Min) when the onHand drops below Min I want to have some kind of alert. The problem I am having is that I am giving the values to a messagebox so I can see what is happening and if I put the ‘onHand’ value in the top ‘if’ block it always comes out as zero but ‘min’ outputs the correct values. If I put the ‘Min’ value in the top ‘if’ block THAT comes out as zero and the ‘onHand’ shows the correct value. I have been trying toi fix it for a while now and can’t figure out what I am doing wrong. Currently I have ‘min’ in the top ‘if’ block and the messagebox always shows min as zero but gives ‘onHand’ the correct value.

The code:

 private void btnLows_Click(object sender, EventArgs e)
    {

        int onHand = 0;
        int min = 0;
        int counter;


        for (counter = 0; counter < (dataGridView1.Rows.Count);
               counter++)
        {
            if (dataGridView1.Rows[counter].Cells["min"].Value
            != null)
            {
                if (dataGridView1.Rows[counter].Cells["min"].Value.ToString().Length != 0)
                {
                   onHand = int.Parse(dataGridView1.Rows[counter].Cells["min"].Value.ToString());

                   if (dataGridView1.Rows[counter].Cells["onHand"].Value != null)
                   {
                       if (dataGridView1.Rows[counter].Cells["onHand"].Value.ToString().Length != 0)
                       {
                           onHand = int.Parse(dataGridView1.Rows[counter].Cells["onHand"].Value.ToString());

                           if (onHand < min)
                           {
                               MessageBox.Show(onHand.ToString(), min.ToString());
                           }
                           else
                           {
                               MessageBox.Show(onHand.ToString(), min.ToString());
                           }
                       }
                   }
                }

            }
  • 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-09T09:45:01+00:00Added an answer on June 9, 2026 at 9:45 am

    This line (inside the first nested if-statement within your for-loop):

    onHand = int.Parse(dataGridView1.Rows[counter].Cells["min"].Value.ToString());
    

    Should probably be:

    min = int.Parse(dataGridView1.Rows[counter].Cells["min"].Value.ToString());
    

    Currently you never set min to anything else but 0 when you define it.

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

Sidebar

Related Questions

I have strange stacktrace when click to submit button (this code is rendered but
I have strange behavior with android.R.layout.simple_dropdown_item_1line while using MultiAutoCompleteTextView . The code I use
I have strange problem on my pc/server. I run query such as Select field1,
I have strange problem with run .exe program in my WebApplication. It works fine
Good day! I have strange problem with Xcode 4.3. When I'm trying to run
Strange performance outcome, I have a LINQ to SQL query which uses several let
I have strange problem. I have class which behaves similar dropdown list. package test.view;
I have strange problem... My file strings.xml contains: <?xml version=1.0 encoding=utf-8?> <resources> <string name=building_name>My
I have a strange problem regarding null pointer exception. I'm posting the problematic code
I have this strange issue where anytime I open a XAML file that contains

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.