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
close icon

TimeSpan TextBox custom format

Hi,
I have a question about TimeSpan Cell.
I set the cell information like that:

CellType = "TextBox";
CellValueType = typeof(TimeSpan);
CellValue = TimeSpan.Parse(s);

and subscribe the Model.QueryCellFormattedText event to format the display text. However, if I want to give several valid TimeSpan format in the TextBox, What can I do?
For example: Besides permit "dd.hh:mm:ss", also permit user inputing: "1 days 2 hours 3 minutes 4 seconds" and "1d2h3m4s"

Thanks


1 Reply

HA haneefm Syncfusion Team November 14, 2007 04:07 PM UTC

Hi Kolauy,

One you can handle the QueryCellFormattedText event handler of the Grid to format the several TimeSpan cell as desired. Please try code below.

bool IsTimeSpanTextWithGeneralFormat = true;
void Model_QueryCellFormattedText(object sender, GridCellTextEventArgs e)
{
if (e.Style.CellValueType == typeof(TimeSpan))
{
TimeSpan tsp;
if (TimeSpan.TryParse(e.Value.ToString(), out tsp))
{
if( IsTextWithTimeSpanGeneralFormat )
e.Text = "TimeSpan" + e.Value ; //your custom formatted text here
else
{
string DisplayText = string.Format("{0}days{1}hour{2}minutes", tsp.Days, tsp.Hours, tsp.Minutes);
e.Text = DisplayText;
}
e.Handled = true;
}
}
}

Best regards,
Haneef


Loader.
Live Chat Icon For mobile
Up arrow icon