We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Timespan formatting

Hi there

I have a typed dataset that has a Timespan column called "ElapsedTimeSecs". I bind this to a GDBG, and then set the format as follows:

dbg.Binder.InternalColumns("ElapsedTimeSecs").StyleInfo.Format = "mm:ss"

The formatting is not applied however? I have used this technique for DateTime columns with no problem. Any ideas please

Cheers,

j

1 Reply

RA Rajagopal Syncfusion Team August 22, 2007 09:17 PM UTC

Hi John,

Thanks for your interest in Syncfusion Products.

You need to handle the QueryCellFormattedText event handler of the GridDataBoundGrid to format the TimeSpan column as desired. Please try code below.

// Form Load
dbg.Binder.InternalColumns("ElapsedTimeSecs").StyleInfo.CellValueType = typeof(TimeSpan)

// grid.Model.QueryCellFormattedText

void Model_QueryCellFormattedText(object sender, GridCellTextEventArgs e)
{
if (e.Style.CellValueType == typeof(TimeSpan))
{
string s = e.Style.Text;
TimeSpan timespan = (TimeSpan)e.Value;
string formatValue = string.Format("{0}:{1}", timespan.Minutes, timespan.Seconds);
e.Text = formatValue;
e.Handled = true;
}
}

Let me know if this helps.

Have a nice time.
Regards,
Rajagopal

Loader.
Live Chat Icon For mobile
Up arrow icon