---
title: "Compare datagrid rows with each other"  
description: "Compare datagrid rows with each other"  
author: "Demir ACAR"  
published: 2014-05-22  
updated: 2014-05-27  
canonical: https://www.mindstick.com/forum/2020/compare-datagrid-rows-with-each-other  
category: "c#"  
tags: ["c#"]  
reading_time: 3 minutes  

---

# Compare datagrid rows with each other

if my [grid](https://www.mindstick.com/forum/369/how-can-i-add-a-column-name-to-my-grid) has a this [value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages)\
\
Number \
90 \
90 \
\
or \
\
Number \
90 \
80 \
\
\
this [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) is working .\
\

```
 for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)            {                for (int ii = i + 1; ii < dataGridView1.Rows.Count; ii++)                                   {                        if (dataGridView1.Rows[i].Cells[0].Value.ToString() == dataGridView1.Rows[ii].Cells[0].Value.ToString())                        {                            MessageBox.Show("Test");                        }                        else                        {                            MessageBox.Show("mest");                        }                    }}}
```

if my grid has a this value ;\
Number \
90 \
80 \
70\
80\
90\
80\
\
above code in looped and not working .

## Replies

### Reply by Demir ACAR

how to skip same value of first

So

10 -- skip this

10 -- Duplicate

10 --Duplicate

20 -- Skip this

20 --Duplicate

20 --Duplicate

\

Thanks .

### Reply by Manmohan Jha

```
 List<string> list = new List<string>();            foreach (DataGridViewRow drow in dataGridView1.Rows)            {                if (list.Contains(drow.Cells[0].Value.ToString()))                {                    MessageBox.Show("Duplicate applied");                }                else                {                    list.Add(drow.Cells[0].Value.ToString());                    MessageBox.Show("Uniq apllied");                }            }
```

### Reply by Demir ACAR

More than 1 unit calculates ;\
Number -Compare - Respond10 12 10-12 - Mest13 10-13 - Mest13 10-13 - Mest ? ? -Mest -Wrong respond ,More than 1 unit calculates ;10 10-10 -Test \
and also I want to compare all row each other if number duplicate applied a condition if number uniq apllied other condition .\
Thanks in dvance .

### Reply by Manmohan Jha

Use this...\
\
List<string> list = new List<string>(); foreach (DataGridViewRow drow in dataGridView1.Rows) { if (list.Contains(drow.Cells[0].Value.ToString())) { MessageBox.Show("Test " + drow.Cells[0].Value); } else { list.Add(drow.Cells[0].Value.ToString()); MessageBox.Show("Mest"); } }


---

Original Source: https://www.mindstick.com/forum/2020/compare-datagrid-rows-with-each-other

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
