Ticket Q276730
Visible to All Users

Formatting Multiple Fields in One Report Label

created 15 years ago

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.

Answers

created 15 years ago

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

    Show previous comments (5)
    DevExpress Support Team 8 years ago

      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 Basic
      Private 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.

        DevExpress Support Team 8 years ago

          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?

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.