C# 从数据源将DateTime绑定到DataGridview中的CalendarColumn
使用这段代码(:C# 从数据源将DateTime绑定到DataGridview中的CalendarColumn,c#,datagridview,C#,Datagridview,使用这段代码(: DataTable dt=newdatatable(); 添加(“选择”,类型(bool)); dt.栏添加(“员工编号”); dt.列。添加(“员工姓名”); 添加(“连接日期”,typeof(DateTime)); 数据行dr; 对于(int i=0;i)您的问题是什么?您是否将日历列添加到网格中并设置了DataPropertyName?“您是否将日历列添加到网格中?”一点也不。就像我没有添加任何CheckboxColumn。但是bool是自动绑定到CheckboxColu
DataTable dt=newdatatable();
添加(“选择”,类型(bool));
dt.栏添加(“员工编号”);
dt.列。添加(“员工姓名”);
添加(“连接日期”,typeof(DateTime));
数据行dr;
对于(int i=0;i)您的问题是什么?您是否将日历列添加到网格中并设置了DataPropertyName
?“您是否将日历列添加到网格中?”一点也不。就像我没有添加任何CheckboxColumn
。但是bool
是自动绑定到CheckboxColumn
的。我想在DateTime
和CalendarColumn
中添加同样的内容。可能绑定不正确,链接更好。。。
DataTable dt = new DataTable();
dt.Columns.Add("Select", typeof(bool));
dt.Columns.Add("Employee No");
dt.Columns.Add("Employee Name");
dt.Columns.Add("Join Date", typeof(DateTime));
DataRow dr;
for (int i = 0; i <= 10; i++)
{
dr = dt.NewRow();
dr["Select"] = false;
dr["Employee No"] = 1000 + i;
dr["Employee Name"] = "Employee " + i;
dr["Join Date"] = DateTime.Now;
dt.Rows.Add(dr);
}
dataGridView1.DataSource = dt;