---
title: "comparison of datagridview cell values"  
description: "comparison of datagridview cell values"  
author: "Anonymous User"  
published: 2014-02-04  
updated: 2014-02-04  
canonical: https://www.mindstick.com/forum/1951/comparison-of-datagridview-cell-values  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# comparison of datagridview cell values

I [am trying](https://answers.mindstick.com/qa/36834/which-two-programming-languages-should-i-master-in-if-i-am-trying-to-get-into-google-or-facebook) to [compare](https://www.mindstick.com/forum/2036/propertyinfo-getvalue-unable-to-compare-datetimes) [values of two](https://www.mindstick.com/forum/158951/how-to-swap-the-values-of-two-variables-without-using-a-temporary-variable-in-python) [datagridview](https://www.mindstick.com/articles/607/working-with-datagridview-in-vc-sharp) cells:

```
if (kk.BoringData.Rows[rows].Cells[0].Value !=kk.BoringData.Rows[rows - 1].Cells[0].Value){}
```

Both cell values are "B-1", but it returns true.

## Replies

### Reply by Pravesh Singh

Hi Goti,\

The Value property is of type object, meaning the != operator tests for reference equality (whether the two objects occupy the same location in memory). To compare the strings by their [values](https://www.mindstick.com/forum/327/sum-textbox-values) you can try using Equals:

if (!kk.BoringData.Rows[rows].Cells[0].Value.Equals(kk.BoringData.Rows[rows - 1].Cells[0].Value))

Or convert them to strings before testing them like this:

if (kk.BoringData.Rows[rows].Cells[0].Value.ToString() != kk.BoringData.Rows[rows - 1].Cells[0].Value.ToString())


---

Original Source: https://www.mindstick.com/forum/1951/comparison-of-datagridview-cell-values

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
