Search code examples
devexpresslabelxtrareport

How to deal with Auto Width property for labels in Reports Devexpress?


Am designing simple report in Devexpress. I add three labels continuously in xtrareport. 1st label & last label are set in designer screen but middle label data comes from database it may be (big or small) word or sentence. If data comes from database big means 3rd label get overlap with this data. How to solve this ?? Thanks in advance.


Solution

  • 0. Three labels.
    In report designer set the width of you 2nd label as more as possible:
    Width of 2nd label

    Set the CanShrink, CanGrow, Multiline and WordWrap to true:

    xrLabel2.CanShrink = true;
    xrLabel2.CanGrow = true;
    xrLabel2.Multiline = true;
    xrLabel2.WordWrap = true;
    

    In result you will get something like this:
    The result

    1. One label with special format.
    You can use one label with format string. Use {0} as placeholder for your data source values:

    xrLabel1.DataBindings.Add(new XRBinding("Text", null, "Value", "Here is the text: «{0}». Here is the end."));
    

    Label with format string.

    Also you can set the CanShrink, CanGrow, Multiline and WordWrap to true.

    The result will be something like this:
    Result with one label

    2. One label with [brackets] in the labels's text.
    You can insert a data field name with [brackets] into the control's text. For example:

    xrLabel1.Text = "Here is the text: «[Value]». Here is the end."
    

    Label with [brackets]

    And here is the result: Result with [brackets]