Change Datagridview Odd and even rows color C#





You can change Datagridview odd and even rows color by adding this code
C#:

  foreach (DataGridViewRow row in dataGridView1.Rows)
  {
            if (row.Index % 2==0 )
            {
                row.DefaultCellStyle.BackColor = Color.Green;    
            }
            else
             {
                row.DefaultCellStyle.BackColor = Color.LimeGreen;
              }

   }


or you can use AlternatingRowsDefaultCellStyle from designer

or by code :


dataGridView1.RowsDefaultCellStyle.BackColor = Color.Green;

   dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.LimeGreen;




First


EmoticonEmoticon