Small example of interlaced color change for the WinForm DataGridView control

  • 2020-05-09 19:12:34
  • OfStack


 dgv.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.White;

Interlaced discoloration


/// <summary>
         ///  Interlaced discoloration 
         /// </summary>
         /// <param name="dgv"> The incoming DataGridView Controls the name </param>
         public static void DgvRowColor(System.Windows.Forms.DataGridView dgv)
         {

             if (dgv.Rows.Count != 0)
             {
                 for (int i = 0; i < dgv.Rows.Count; i++)
                 {
                     if ((i + 1) % 2 == 0)
                     {
                         dgv.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.White;
                     }
                     else
                     {
                         dgv.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.FromArgb(224, 254, 254);
                     }                  
                 }
             }
         }


Related articles: