Home Forums WinForms controls Xceed Grid for WinForms how to format system.timespan to hh:mm

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #15242 |

    i have a field that is of system.timespan datatype.

    how do i format it so that it comes out as HH:mm rather than hh:mm:ss?
    is there an editor as well that will validate this format?

    i tried most of the formatting options found on the forum but they only work if the field is of datetime format.

    thanks

    Imported from legacy forums. Posted by wtchout (had 2838 views)

    User (Old forums)
    Member
    Post count: 23064

    This will not be possible unless you create your own CellViewerManager, so that you can dictate the display format.

    Here is more detail on how to expend on CellViewerManager :

    http://doc.xceedsoft.com/products/XceedGrid/Custom_CellViewMangers_and_Reports.html
    http://doc.xceedsoft.com/products/XceedGrid/Deriving_from_the_CellViewerManager_class.html
    http://doc.xceedsoft.com/products/XceedGrid/BooleanImageTextViewer_class.html

    Imported from legacy forums. Posted by André (had 256 views)

    User (Old forums)
    Member
    Post count: 23064

    <pre>class TimeSpanCellViewer : CellViewerManager
    {
    protected override string GetTextCore(object value, CellTextFormatInfo formatInfo, GridElement gridElement)
    {
    if (value == null || value is DBNull || value == formatInfo.NullValue)
    return formatInfo.NullText;

    if (value is TimeSpan)
    {
    TimeSpan lValue = (TimeSpan)value;
    return string.Format(“{0}:{1}”, lValue.Hours, lValue.Minutes);
    }

    return value.ToString();
    }
    }</pre>

    Imported from legacy forums. Posted by Tommy (had 663 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks Tommy 🙂

    Imported from legacy forums. Posted by André (had 3919 views)

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.