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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:29:47+00:00 2026-05-15T02:29:47+00:00

This is something I thought would be easier than it’s turning out to be.

  • 0

This is something I thought would be easier than it’s turning out to be. For whatever reason, I can’t seem to figure out a way to make what I’m trying to do here work with an If statement:

  List<int> miscTimes = new List<int>();

            for (int i = 0; i < MISCdataGridView1.RowCount; i++)
            {
                if (MISCdataGridView1.Rows[i].Cells[2].Value == "Something")
                {
                    miscTimes.Add(Convert.ToInt32(MISCdataGridView1.Rows[i].Cells[3].Value));
                }
            }
            return miscTimes;

For some reason, I can’t get it to like anything I do with the if statement:

if (MISCdataGridView1.Rows[i].Cells[2].Value == "Something")

it doesn’t throw an exception, but it’s not building my list. It has the green underline and says “Possible unintended reference comparison; cast the left side type to ‘string'”
I’ve tried converting to string and all of that. How should I go about this?

  • 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-05-15T02:29:48+00:00Added an answer on May 15, 2026 at 2:29 am

    The DataGridViewCell.Value property is of type Object and therefore you have to cast to String

    (String)dataGridview.Rows[i].Cells[j].Value == "Something"
    

    or rely on Object.Equals().

    Object.Equals(dataGridview.Rows[i].Cells[j].Value, "Something")
    

    Using Object.Equals() is more robust because it can deal with the value not being of type String. On the other hand using the cast emphasizes the fact that the value must be a String and will throw an exception if it is not – clearly showing that you probably have a bug.

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

Sidebar

Related Questions

I'm working on a simple application to start learning my way around WPF. I
EDIT: I would love to read reactions to Steve Reed's AOP approach. Comments to
My application is intended to work almost entirely through a Windows 7 taskbar item
The problem We need to defend against a 'WAITFOR DELAY' sql injection attack in
I'm currently trying to add gridlines to a canvas. I need an exact free
I am new to PHP and programming in general. I have been working on
Ok, so it's almost as easy as pie already. But it really should be
I was recently advocating to a colleague that we replace some C# code that
I have some logic, which defines and uses some user-defined types, like these: class

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.