c# - Show only Date in Column of DataGridView -
this question has answer here:
- show date in datagridview column 1 answer
i have date store in mysql database format datetime
.
i want put only date in 1 datagridview
when try date following hours, like:
29/06/2016 12:01:21
i tried find date directly mysql query using date()
function, still not work because in datagridview
see date formatted follows:
29/06/2016 00:00:00
finally tried side code set column, without result
datagridview.columns[1].defaultcellstyle.format = "dd/mm/yyyy";
i use datasource
"link" data datagridview
.
this code:
var datatable = listofresult.todatatable(); //todatatable() function convert list datatable datagridview.datasource = datatable; datagridview.columns[1].defaultcellstyle.format = "dd/mm/yyyy";
the listofresult
list of such dynamic , inside there dates.
function todatatable()
public static datatable todatatable(this ienumerable<dynamic> items) { var data = items.toarray(); if (!data.any()) return null; var dt = new datatable(); foreach (var key in ((idictionary<string, object>) data[0]).keys) dt.columns.add(key); foreach (var d in data) dt.rows.add(((idictionary<string, object>) d).values.toarray()); return dt; }
taw's right. set datatype: replace
dt.columns.add(key);
with
dt.columns.add(key, typeof(datetime));
for desired columns.
Comments
Post a Comment