I've seen how to format data for one field in a label while adding additional text by using the format string. Is it possible to format multiple fields in one label control? I have a start / end date in one label, and I need to have both of them in a certain date format. Just wondering if this is possible.
Formatting Multiple Fields in One Report Label
Answers
Hi Ryan,
Yes, it's possible, please use the following code : [MyFieldName!Formatstring] to accomplish this task.
Please try this solution, and let us know the results.
Thanks,
Andrew
Hello,
Thank you for the clarification. To accomplish this task. handle the XRLabel.BeforePrint event in the following manner:
C#private void label1_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) {
XRLabel label = sender as XRLabel;
DateTime dateTimeValue = DateTime.Parse(label.Text);
if(dateTimeValue.TimeOfDay.Hours != 0 || dateTimeValue.TimeOfDay.Seconds != 0 || dateTimeValue.TimeOfDay.Minutes != 0)
label.Text = String.Format("{0:dd.MM.yyyy hh:mm}", dateTimeValue);
else
label.Text = String.Format("{0:dd.MM.yyyy}", dateTimeValue);
}
Visual BasicPrivate Sub label1_BeforePrint(sender As Object, e As System.Drawing.Printing.PrintEventArgs)
Dim label As XRLabel = TryCast(sender, XRLabel)
Dim dateTimeValue As DateTime = DateTime.Parse(label.Text)
If dateTimeValue.TimeOfDay.Hours <> 0 OrElse dateTimeValue.TimeOfDay.Seconds <> 0 OrElse dateTimeValue.TimeOfDay.Minutes <> 0 Then
label.Text = [String].Format("{0:dd.MM.yyyy hh:mm}", dateTimeValue)
Else
label.Text = [String].Format("{0:dd.MM.yyyy}", dateTimeValue)
End If
End Sub
See the attached video showing the result.
Thank you for quick answer!
Unfortunately, the suggested approach does not fit me cause I need to implement this on designer side. So please tell me if it is possible to use some approach based on the syntax "[MyFieldName!Formatstring]" to achieve my goal.
Hello,
I'm afraid your task is unclear to me. The solution I posted in my previous comment works when the Preview tab of the End-User Designer is activated. Would you please describe your task in greater detail?