cannot able to set row header value in datagridview

Apr 23 2013 4:08 PM
Hi friends 

i have develop two windows form .
in first form
 
the code for add row and column and set the rowheader text. the code is below

DataTable dt = new DataTable();

for (int i = 0; i < columncount; i++)
{ dt.Columns.Add();
}
for (int j = 0; j < rowcount; j++)
{
dt.Rows.Add();
}
dataGridView1.DataSource = dt;
for( int i=0;i<rowcount;i++)
{
dataGridView1.Rows[i].HeaderCell.Value = (i + 1).ToString();
}

This code works for setting headercell of rows in gridview. and in the another form gridview design for time table it does not show the row headercell.value. the code is 

DataTable result= userdao.getdateanddayfortimetable1(comp);
DataTable period = userdao.getperiodfortimetable();
int periodcount = period.Rows.Count;
int daycount = result.Rows.Count;
DataTable dt = new DataTable();
for (int i = 0; i < periodcount; i++)
{
dt.Columns.Add();
}
for (int j = 0; j < daycount; j++)
{
dt.Rows.Add();
}
  for (int k = 0; k < periodcount; k++)
{
  dt.Columns[k].ColumnName = period.Rows[k]["PeriodNo"].ToString() + "(" + period.Rows[k]["StartTime"].ToString() + "-" + period.Rows[k]["EndTime"].ToString() + ")";
}
PLayer.TimeTable timetable = new PLayer.TimeTable();
timetable.timetablegrid.DataSource = dt;

for (int i = 0; i < daycount; i++)
{
timetable.timetablegrid.Rows[i].HeaderCell.Value = result.Rows[i]["Working_day"].ToString(); //timetable.timetablegrid.RowTemplate.Height = 25; //timetable.timetablegrid.RowHeadersDefaultCellStyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
}
timetable.Show(); 



from yesterday i stuck with this problem. i dont know how to solve this problem. help me to solve this problem.
Thank you