List of Exercises

Alternating Row Backcolor of Datagridview in WinForms C#

	    
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Alternating_Rows_Style_Datagridview
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
      /*
      DataTable dt = new DataTable();
      dt.Columns.Add("First Name");
      dt.Columns.Add("Last Name");
      DataRow dr1 = dt.NewRow();
      dr1[0] = "James";
      dr1[1] = "Smith";
      dt.Rows.Add(dr1);
      DataRow dr2 = dt.NewRow();
      dr2[0] = "Maria";
      dr2[1] = "Garcia";
      dt.Rows.Add(dr2);
      DataRow dr3 = dt.NewRow();
      dr3[0] = "David";
      dr3[1] = "Rodriguez";
      dt.Rows.Add(dr3);
      DataRow dr4 = dt.NewRow();
      dr4[0] = "John";
      dr4[1] = "Johnson";
      dt.Rows.Add(dr4);
      */
      DataTable dt = new DataTable();
      dt.Columns.Add("rank");
      dt.Columns.Add("England 2015");
      dt.Columns.Add("England past 100 years");
      dt.Columns.Add("USA 2014");
      dt.Columns.Add("USA past 100 years");
      dt.Rows.Add(new object[]{ "1", "Oliver", "Jake", "Noah", "James" });
      dt.Rows.Add(new object[]{ "2", "Jack", "Connor", "Liam", "John" });
      dt.Rows.Add(new object[]{ "3", "Harry", "Callum", "Mason", "Robert" });
      dt.Rows.Add(new object[]{ "4", "Jacob", "Jacob", "Jacob", "Michael" });
      dt.Rows.Add(new object[]{ "5", "Charlie", "Kyle", "William", "William" });
      dt.Rows.Add(new object[]{ "6", "Thomas", "Joe", "Ethan", "David" });
      dt.Rows.Add(new object[]{ "7", "George", "Reece", "Michael", "Richard" });
      dt.Rows.Add(new object[]{ "8", "Oscar", "Rhys", "Alexander", "Joseph" });
      dt.Rows.Add(new object[]{ "9", "James", "Charlie", "James", "Charles" });
      dt.Rows.Add(new object[]{ "10", "William", "Damian", "Daniel", "Thomas" });
      dataGridView1.DataSource = dt;
    }
	private void apply_style_Click(object sender, EventArgs e)
    {
      dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.Blue;
      dataGridView1.EnableHeadersVisualStyles = false;

      dataGridView1.DefaultCellStyle.BackColor = Color.LightSteelBlue;
      dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.SteelBlue;
    }
  }
}
		
	 


Download the project of Visual Studio 2013 in DropBox Download


Alternating Row Backcolor of DataGridView in WinForms C#


Video Thumbnail