HOW TO DO THE COLOR FOR A PARTICULAR ROW IN A GRIDVIEW?

Jeet Verma

Total Post:110

Points:776
Posted by  Jeet Verma
 798  View(s)
Ratings:
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;

    }                      

}

  1. Samuel Fernandes

    Post:159

    Points:1117
    Re: How to do the color for a particular row in a gridview?

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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!