Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7504705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:39:42+00:00 2026-05-29T21:39:42+00:00

Is there an easy way to show a formatted string representing a TimeSpan field

  • 0

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:

  • https://connect.microsoft.com/VisualStudio/feedback/details/94492/timestamp-class-should-be-xml-serializable

  • http://forums.silverlight.net/t/51793.aspx

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T21:39:42+00:00Added an answer on May 29, 2026 at 9:39 pm

    Create a read-only string property in your object that will represent the formatted TimeSpan. Something like:

    public class MyObject
    {
    private TimeSpan _myTimeSpan;
    
    // ...
    
    public string TimeSpanFormatted
    {
        get
        {
             return _myTimeSpan.ToString("c");
        }
    }
    
    // ...
    }
    

    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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there an easy-ish way to modify the webform-form-tpl.php template to show disclaimer text
Is there an easy way to iterate over an associative array of this structure
Is there an easy way to capitalize the first letter of a string and
Is there an easy way to show whether there are any symlinks in a
Is there an easy way to show the properties dialog for a file in
is there any easy way to show images in asp.net page from a ftp
Is there an easy way to do the following: I have an application which
Is there an easy way to add a checkbox (or any other custom control,
Is there an easy way to show a project manager a few grpahics/numbers how
Is there any easy and clean way to show a message box in Qt4

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.