C#: custom celltemplate is not invalidating in datagridview?

心不动则不痛 提交于 2020-01-06 04:32:46

问题


I am displaying some data in datagridview whose datasource is a datatable.

For DateTime column, I want to use datetimepicker control to edit the value. So I tried the following code found in this link. https://msdn.microsoft.com/en-us/library/7tas5c80

After assigning the custom cell template to the DateTime column, datagridview is not invalidating immediately.

Here is the code I tried

dataGridView1.DataSource = dataTable;

CalendarCell cell = new CalendarCell();
this.dataGridView1.Columns["DATE"].CellTemplate = cell;
this.dataGridView1.Invalidate();

When I sort any column in datagridview. Then the custom template works.

I tried this also, still it is not working.

dataGridView1.InvalidateColumn(2);

How do I tell datagridview to invalidate immediately so that custom template works properly without the need of sorting the column?

来源:https://stackoverflow.com/questions/34550178/c-custom-celltemplate-is-not-invalidating-in-datagridview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!