Click here to Skip to main content
16,022,418 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends
This is my complete code for timetable design format using datagridview.
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.Show();


rowheader text not visible in the output of the datagridview.how can fix the problem.
 for (int i = 0; i < daycount; i++)

            {
timetable.timetablegrid.Rows[i].HeaderCell.Value=(i+1).Tostring()
}

this code working in another datagridview but not in this gridview. i dont know what would be the problem?
Posted
Updated 23-Apr-13 19:16pm
v4
Comments
Richard C Bishop 23-Apr-13 17:37pm    
I do not see where you are setting the datasource. How is the datagridview going to display anything?
baskaran chellasamy 23-Apr-13 18:01pm    
before this for loop i set the datasource to datagridview. full 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();
}
//System.Windows.Forms.DataGridView grid = new System.Windows.Forms.DataGridView();
PLayer.GenerateTimetable gt = new PLayer.GenerateTimetable();
// gt.dataGridView1.DataSource = dt;

for (int k = 0; k < periodcount; k++)
{
//gt.dataGridView1.Columns[k].HeaderText
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 m = 0; m < daycount; m++)
//{
// string rowheader = result.Rows[m]["Working_day"].ToString();
// timetable.timetablegrid.Rows[m].HeaderCell.Value = rowheader;

//}
for (int i = 0; i < daycount; i++)
{
//System.Windows.Forms.DataGridViewRow row = new System.Windows.Forms.DataGridViewRow();
//row.HeaderCell.Value = result.Rows[i]["Working_day"].ToString();
timetable.timetablegrid.Rows[i].HeaderCell.Value = result.Rows[i]["Working_day"].ToString();
}


timetable.Show();

in this first two datatable contains data for setting columnname and rowheader and how many row and column need to be create. here i already set column name but i cannot able to set rowheader. even i try the following code for checking
timetable.timetablegrid.Rows[i].HeaderCell.Value=(i+1).ToString(), still it does not work. but the same code working in another gridview for rowheader text. thats why i am stuck here.
Naz_Firdouse 24-Apr-13 1:22am    
may be some styling issue. check that...
baskaran chellasamy 24-Apr-13 1:54am    
sorry i stuck with this problem from yesterday.
when i go through the code in for loop, it set the row[i].headercell.value to the particular string.but when datagridview shows, row header text not appear. i check all the properties and i confused why in this gridview only not showing text in row header

1 solution

I know it's a little late to answer this question, but maybe somebody else will have the same problem. Check if the form which contains the grid view where the header cell is not displayed has a MDI parent. If it has, please remove the MDI parent.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900