❔ Format column DataGridview in WPF
I have the following epooch time data from a csv that I'm trying to import into a datagrid. What code can we use within the grid to convert it to regular Date Time format ie. 12/14/2022 3:00pm etc. ?
1671026261
5 Replies
I think you can get a datetime from an epoch value like this:
then to get it to display in your datagridview depends on how you are binding the data, which could be a myriad of ways so its hard to say without knowing but the easiest way would be to just expose a property with the conversion above and bind to that.
Do you have a link where they do this approach? Not sure what I'd be looking for. 😄 I'm binding it with a datatable. It's autogenerating columns. How can we expose the property?
Ok in that case if you are binding directly to the datatable then you can create a converter to handle the datetime.
For example given this xaml:
And this view model:
You could make this converter:
Which would result in this table:
You can find a working example of this here: https://github.com/AlexLexicon/Discord.Example.DataGridviewEpoch
GitHub
GitHub - AlexLexicon/Discord.Example.DataGridviewEpoch
Contribute to AlexLexicon/Discord.Example.DataGridviewEpoch development by creating an account on GitHub.
Great gonna check it out
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.