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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:46:46+00:00 2026-06-16T04:46:46+00:00

I have a datagridview in a C# winforms app, and I’m comparing the values

  • 0

I have a datagridview in a C# winforms app, and I’m comparing the values in a certain cell in each row to an item in an array that I read into from a file.

 foreach (DataGridViewRow dr in dataGridView2.Rows)
                {
                    if (dr.Cells[AcctNoIndex-1].Value == items[custAcctNo-1])//row in datagridview that contains the customer account number
                    {
                        items[custState-1] = dr.Cells[ShipStateIndex-1].Value.ToString();
                        items[custCountry-1] = dr.Cells[ShipCountryIndex-1].Value.ToString();
                        items[custShipState-1] = dr.Cells[ShipStateIndex-1].Value.ToString();
                        items[custShipCountry-1] = dr.Cells[ShipCountryIndex-1].Value.ToString();
                    }

                }

So, for each row dr in the datagridview, I look at the cell at AcctNoIndex-1. If that value equals the value in this array I read some data into, items[custAcctNo-], I do the following stuff.

I was debugging the code, however, and I noticed in the Watch window, that items[custAcctNo-1] was the same as dr.Cells[AcctNoIndex-]. For one of the rows, the values are the same. However, when I step through the debugger, the program skips everything in the if block and just continues.

My debugging output

Can anyone help me with this? I think that since both values are strings, the condition should be true, and the program should continue in the if block, but I’m confused as to why the debugger thinks the two values are not the same.

  • 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-16T04:46:47+00:00Added an answer on June 16, 2026 at 4:46 am

    One says string, one is an object. Cast them both to strings and it will work.

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

Sidebar

Related Questions

I have a DataGridView in a Winforms app that has about 1000 rows (unbound)
I have a Winforms app that has a DataGridView that is databound at runtime.
I have a winforms datagridview that seems to always have at least one row
I have a DataGridView control in a winforms app that I'm working on. The
I have a DataGridView in a C# WinForms app that is DataBound at runtime
This is a VB.NET, Winforms App. I have a datagridview on Form1 that uses
I have a DataGridView in a WinForms 2.0 App that has a lot of
On my Winforms app, I have a primary form with a DataGridView bound to
I have a DataGridView in a Winforms application containing a collection of items. Each
Please advise me. Winforms app, C#. I have a user control (UC) 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.