---
title: "How to do the color for a particular row in a gridview?"  
description: "How to do the color for a particular row in a gridview?"  
author: "Anonymous User"  
published: 2015-03-10  
updated: 2015-03-10  
canonical: https://www.mindstick.com/forum/13012/how-to-do-the-color-for-a-particular-row-in-a-gridview  
category: ".net"  
tags: ["c#", ".net", "winforms", "datagridview"]  
reading_time: 1 minute  

---

# How to do the color for a particular row in a gridview?

I am using two [forms](https://www.mindstick.com/interview/34192/what-is-the-purpose-of-the-authentication-mode-forms-element-in-web-config),when I am sending the StockID from one [form](https://www.mindstick.com/forum/6/multi-form-mfc-application) to another form,in the [second](https://answers.mindstick.com/qa/41761/how-did-the-second-industrial-revolution-influence-women-s-roles-in-society) form there is some [data](https://www.mindstick.com/articles/13050/salesforce-aiming-to-dominate-predictive-analytics-with-data-science) in the [gridview](https://www.mindstick.com/articles/873/update-delete-edit-gridview-in-asp-dot-net),[now](https://yourviews.mindstick.com/view/81402/it-s-liberals-vs-progressives-in-us-politics-now) I [wan](https://www.mindstick.com/forum/157828/explain-the-difference-between-lan-and-wan-what-are-the-use-cases-for-each-type-of-network) to do tat is,by using that id I want to highlight the that row only. I want to [compare](https://www.mindstick.com/forum/2036/propertyinfo-getvalue-unable-to-compare-datetimes) the ID is [exists](https://www.mindstick.com/forum/158947/how-do-you-use-the-exists-operator-to-check-for-the-existence-of-records-in-a-subquery) in the gridview or not,if exits the I want to Do the higlighten for that [full](https://www.mindstick.com/articles/12893/experience-the-full-power-of-suitecrm) row.,

\

```
if (pc == c){    for (int i = 0; i
< grid_stock.Rows.Count; i++)    {       grid_stock.SelectionMode = DataGridViewSelectionMode.FullRowSelect;       this.grid_stock.Rows[i].DefaultCellStyle.BackColor = Color.Red;        break;    }                       }
```

## Replies

### Reply by Samuel Fernandes

Try this,

Give correct column index of StockID in row.Cells[0]

```
foreach (DataGridViewRow row in grid_stock.Rows) {  if
(row.Cells[0].Value.Equals("StockID"))   {   
grid_stock.SelectionMode = DataGridViewSelectionMode.FullRowSelect;   
row.DefaultCellStyle.BackColor = Color.Red;   }}
```


---

Original Source: https://www.mindstick.com/forum/13012/how-to-do-the-color-for-a-particular-row-in-a-gridview

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
