Is there an easy way to show a formatted string representing a TimeSpan field in a DataGridViewTextBoxColumn of a DataGridView?
I have an array of custom objects (returned by a web service) that I’m binding to my datagrid. These object have a TimeSpan property. When I bind this property to the column of the datagrid I obtain the object name (something like MyApplication.MyClass.TimeSpan) and not the timespan string.
How can I solve?
NOTE:
At last I discovered my problem is that I get my array of objects from a web service.
It seems that TimeSpan type cannot be xml-serialized, so the system class is re-classed into a custom object:
Create a read-only string property in your object that will represent the formatted TimeSpan. Something like:
Then add a column for this property and hide the “raw” TimeSpan column.
See here for TimeSpan formatting info.
NOTE: For your column’s properties be sure to set the DataMember to TimeSpanFormatted