TimeSpanStringConvertEventArgs.Handled Property
Gets or sets whether an event was handled, if it was handled the default actions are not required.
Namespace: DevExpress.XtraScheduler.Native
Assembly: DevExpress.XtraScheduler.v24.2.Core.Desktop.dll
NuGet Package: DevExpress.Scheduler.CoreDesktop
#Declaration
#Property Value
Type | Description |
---|---|
Boolean | true if default conversion isn’t required; otherwise, false. |
#Remarks
The HumanReadableTimeSpanHelper.ParseString and HumanReadableTimeSpanHelper.ConvertToString events fire before the standard conversion procedure of a TimeSpan value to a string or vice versa is started. If the event parameter’s Handled property is set to true within a handler, then the default conversion will not be performed. Otherwise, any custom conversion performed within an event handler will be overridden by the HumanReadableTimeSpanHelper‘s standard conversion routines.
#Example
This example demonstrates how to use the HumanReadableTimeSpanHelper instance to implement the custom conversion of a TimeSpan value to a string and vice versa. To do this handle the HumanReadableTimeSpanHelper.ParseString and HumanReadableTimeSpanHelper.ConvertToString events and use the members of the corresponding TimeSpanStringConvertEventArgs object.
using DevExpress.XtraScheduler.Native;
// ...
// Handle the ParseString and ConvertToString events of the HumanReadableTimeSpanHelper.
HumanReadableTimeSpanHelper.ParseString += new TimeSpanStringConvertEventHandler(OnParse);
HumanReadableTimeSpanHelper.ConvertToString += new TimeSpanStringConvertEventHandler(OnToString);
// Custom parsing of a string to a TimeSpan value.
void OnParse(object sender, TimeSpanStringConvertEventArgs e) {
double val;
try {
string number = e.StringValue.Substring(0, e.StringValue.IndexOf(" milliseconds"));
val = Convert.ToDouble(number);
}
catch {
val = 0;
}
e.TimeSpanValue = TimeSpan.FromMilliseconds(val);
e.Handled = true;
}
// Custom conversion of a TimeSpan value to a string.
void OnToString(object sender, TimeSpanStringConvertEventArgs e) {
e.StringValue = e.TimeSpanValue.TotalMilliseconds.ToString() + " milliseconds";
e.Handled = true;
}