C#:自定义celltemplate在datagridview中没有失效?

C#:自定义celltemplate在datagridview中没有失效?,c#,winforms,datagridview,datetimepicker,celltemplate,C#,Winforms,Datagridview,Datetimepicker,Celltemplate,我正在datagridview中显示一些数据,其数据源是datatable 对于DateTime列,我想使用datetimepicker控件编辑该值。 因此,我尝试了在该链接中找到的以下代码。 将自定义单元格模板分配给DateTime列后,datagridview不会立即失效 这是我试过的代码 dataGridView1.DataSource = dataTable; CalendarCell cell = new CalendarCell(); this.dataGridView1.Col

我正在datagridview中显示一些数据,其数据源是datatable

对于DateTime列,我想使用datetimepicker控件编辑该值。 因此,我尝试了在该链接中找到的以下代码。

将自定义单元格模板分配给DateTime列后,datagridview不会立即失效

这是我试过的代码

dataGridView1.DataSource = dataTable;

CalendarCell cell = new CalendarCell();
this.dataGridView1.Columns["DATE"].CellTemplate = cell;
this.dataGridView1.Invalidate();
对datagridview中的任何列进行排序时。然后自定义模板就可以工作了

我也试过了,但还是不起作用

dataGridView1.InvalidateColumn(2);
如何让datagridview立即失效,以便自定义模板可以正常工作,而无需对列进行排序