This example demonstrates how to create a custom report control and add it to the End-User Report Designer toolbox.
Files to Review
Documentation
More Examples
- How to Create a Custom DevExpress Report Control
- Reporting for Web Forms - Create a Custom Report Control
- Reporting for ASP.NET Core - Create a Custom Report Control
Does this example address your development requirements/objectives?
(you will be redirected to DevExpress.com to submit your response)
Example Code
C#using DevExpress.Utils.Serializing;
using DevExpress.XtraPrinting;
using DevExpress.XtraReports.Localization;
using DevExpress.XtraReports;
using DevExpress.XtraReports.UI;
using System.ComponentModel;
using System.Drawing;
public enum MyEnum { One, Two, Three }
public class MyControl : XRLabel {
public static readonly SizeF InitSizeF = new SizeF(200, 50);
[XtraSerializableProperty,
DefaultValue(true),
Favorite(true),
SRCategory(ReportStringId.CatBehavior)]
public bool BoolProp { get; set; }
[XtraSerializableProperty,
DefaultValue(MyEnum.One)]
public MyEnum EnumProp { get; set; }
[XtraSerializableProperty]
public Item[] ArrayProp { get; set; }
protected override void PutStateToBrick(VisualBrick brick, PrintingSystemBase ps) {
base.PutStateToBrick(brick, ps);
brick.Text = EnumProp.ToString();
}
public class Item {
[XtraSerializableProperty]
public int PropA { get; set; }
}
}
C#using DevExpress.Utils.Serializing;
using DevExpress.XtraPrinting;
using DevExpress.XtraReports.UI;
using System.ComponentModel;
public class NumericLabel : XRLabel
{
[Browsable(true), Bindable(false), Category("Data")]
[XtraSerializableProperty]
[DefaultValue("")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
EditorBrowsable(EditorBrowsableState.Always)]
public int Number { get; set; }
// Render the control in the Designer's Preview and in the document.
protected override void PutStateToBrick(VisualBrick brick, PrintingSystemBase ps)
{
base.PutStateToBrick(brick, ps);
brick.Text = this.Number.ToString();
}
}
Razor@using Reporting_AspNetMvc_Create_Custom_Control
<script type="text/html" id="dxrd-svg-toolbox-numericlabel">
<svg viewBox="-2 -4 32 32" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="Layer_1" transform="translate(-2, -4)" style="enable-background:new 0 0 32 32">
<g id="Window">
<path d="M30, 10L30, 5C30, 4.5 29.5, 4 29, 4L3, 4C2.5, 4 2, 4.5 2, 5L2, 10L30, 10z" fill="#1177D7" class="Blue" />
</g>
</g>
<g id="Layer_1" transform="translate(-2, -4.00000095367432)" style="enable-background:new 0 0 32 32">
<g id="Window">
<path d="M28, 10L28, 26L4, 26L4, 10L2, 10L2, 27C2, 27.5 2.5, 28 3, 28L29, 28C29.5, 28 30, 27.5 30, 27L30, 10L28, 10z" fill="#727272" class="Black" />
</g>
</g>
</svg>
</script>
@Html.DevExpress().ReportDesigner(settings =>
{
settings.Name = "ReportDesigner1";
settings.CustomControlTypes.AddRange(new[] { typeof(MyControl), typeof(NumericLabel) });
}).BindToUrl("TestReport").GetHtml()