Home > DeveloperSection > Forums > How to do the color for a particular row in a gridview?
Jeet Verma
Jeet Verma

Total Post:110

Points:776
Posted on    March-10-2015 4:14 AM

 .NET C#  .NET  Winforms  Datagridview 
Ratings:


 1 Reply(s)
 507  View(s)
Rate this:

I am using two forms,when I am sending the StockID from one form to another form,in the second form there is some data in the gridview,now I wan to do tat is,by using that id I want to highlight the that row only. I want to compare the ID is exists in the gridview or not,if exits the I want to Do the higlighten for that full 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;

    }                      

}



Samuel Fernandes
Samuel Fernandes

Total Post:156

Points:1096
Supported
Posted on    March-10-2015 6:45 AM

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;
  }
}


Don't want to miss updates? Please click the below button!

Follow MindStick