Change Column name(s) in DataGridView
You need to set DataGridView.Column[index].HeaderText:
DateTime dt = DateTime.Now;
string s = dt.DayOfWeek.ToString();
for (int i = 0; i < 10; i++)
{
dataGridView1.Columns.Add(string.Format("col{0}", i), s);
}
for (int i = 0; i < dataGridView1.Columns.Count; i++)
{
string str = dataGridView1.Columns[i].HeaderText;
if (str == "Wednesday")
{
dataGridView1.Columns[i].HeaderText = "fifth day of week";
}
}
Add this line to Datagridview DataBindingComplete event handler
this.dataGridView1.Columns["your database column name"].HeaderText = " preferred name";
The below code will get all days of week after each other between specific datetimes and print the names of the days as column headers:
DateTime dtStart = new DateTime(2012, 11, 1);
DateTime dtEnd = new DateTime(2012, 11, 7);
for (int i = 0; i < dtEnd.Subtract(dtStart).Days; i++)
{
TimeSpan counter = new TimeSpan(i, 0, 0, 0);
dataGridView1.Columns.Add(string.Format("col{0}", i), (dtStart + counter).DayOfWeek.ToString());
}