Skip to main content
A newer version of this page is available. .

XRZipCode Class

Renders a numeric postal code that is used to identify the mail address in some countries. This control is not related to the Zone Improvement Plan (ZIP) code used by the United States Postal Service.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v20.1.dll

NuGet Packages: DevExpress.Reporting.Core, DevExpress.WindowsDesktop.Reporting.Core

Declaration

[DefaultBindableProperty("Text")]
public class XRZipCode :
    XRFieldEmbeddableControl

Remarks

The XRZipCode control renders a numeric postal code that is used to identify the mail address in some countries. This control is not related to the Zone Improvement Plan (ZIP) code used by the United States Postal Service.

RD_Controls_ZipCode

A postal code can only display numeric characters and dashes. Other characters are displayed as empty boxes.

To add this control to a report, drag the XRZipCode item from the DX:20.1: Report Controls Toolbox tab and drop it onto the report.

report-control-zipcode-0

To specify the text for the control, use the XRZipCode.Text property.

Bind a Postal Code to Data

The Text property can be bound to a data field obtained from the data source. To do this, click the control’s smart tag and in its actions list, expand the Expression drop-down list and select the required data field.

report-control-zipcode-2

Clicking the Expression option’s ellipsis button invokes the Expression Editor, in which you can construct a complex binding expression involving two or more data fields.

See the Bind Report Controls to Data topic to learn more about available data binding modes and creating data-aware controls.

Add a Zip Code to End-User Report Designers

The Toolbox of End-User Report Designers does not contain the XRZipCode control by default.

To register this control, do one of the following (depending on your target platform):

  • Windows Forms

    Add the control to the Toolbox of the End-User Report Designer for WinForms by handling the XRDesignMdiController.DesignPanelLoaded event as shown in the following code snippet:

    using System.Drawing.Design;
    using DevExpress.XtraReports.UI;
    using DevExpress.XtraReports.UserDesigner;
    
    private void reportDesigner1_DesignPanelLoaded(object sender, DesignerLoadedEventArgs e) {
        IToolboxService ts = (IToolboxService)e.DesignerHost.GetService(typeof(IToolboxService));
        ToolboxItem item = new ToolboxItem(typeof(XRZipCode));
        item.DisplayName = "Zip Code";
        ts.AddToolboxItem(item);
    }
    

    Add the Zip Code item to the context menu invoked when you right-click a data field in the Field List and drop it onto the report.

    using System.Drawing;
    using System.ComponentModel;
    using DevExpress.XtraReports.UserDesigner;
    using DevExpress.XtraReports.Design;
    using DevExpress.XtraReports.Design.Commands;
    using DevExpress.XtraReports.UI;
    //... 
    
    private void Form1_Load(object sender, EventArgs e) {
        //...
        reportDesigner1.AddService(typeof(IMenuCreationService), new CustomMenuCreationService());
    }
    
    class CustomMenuCreationService : IMenuCreationService {
    
        public MenuCommandDescription[] GetCustomMenuCommands() {
            return new MenuCommandDescription[] {};            
        }
    
        public void ProcessMenuItems(MenuKind menuKind, MenuItemDescriptionCollection items) {
            if (menuKind == MenuKind.FieldDrop) {
                int index = items.IndexOf(BandCommands.BindFieldToXRBarCode);
                if (index < 0)
                    return;
                ToolboxBitmapAttribute bitmapAttribute = (ToolboxBitmapAttribute)TypeDescriptor.
                    GetAttributes(typeof(XRZipCode))[typeof(ToolboxBitmapAttribute)];
                Image itemImage = bitmapAttribute.GetImage(typeof(XRZipCode), false);
                MenuItemDescription zipCodeItem = new MenuItemDescription("Zip Code", itemImage, 
                    BandCommands.BindFieldToXRZipCode);
                items.Insert(index+1, zipCodeItem);
            }
        }
    }
    
  • WPF

    Add the control to the Toolbox of the End-User Report Designer for WPF by calling the static ReportDesigner.RegisterControl<T> method and passing an appropriate diagram item and control icon as parameters.

    using System.Windows.Media.Imaging;
    using DevExpress.Xpf.Reports.UserDesigner;
    using DevExpress.Xpf.Reports.UserDesigner.XRDiagram;
    using DevExpress.XtraReports.UI;
    using DevExpress.Utils;
    using DevExpress.Xpf.Core;
    
    var icon = (ImageSource)new ImageSelectorExtension {
        Source = AssemblyHelper.GetResourceUri(typeof(ReportDesigner).Assembly,
            "Images/Toolbox32x32/XRZipCode.png"),
        SvgSource = AssemblyHelper.GetResourceUri(typeof(ReportDesigner).Assembly,
            "Images/SVG/Controls/XRZipCode.svg")
    }.ProvideValue(null);
    ReportDesigner.RegisterControl<XRZipCode>(() => new DefaultXRControlDiagramItem(), icon);
    
  • ASP.NET

    Add the control to the Web End-User Report Designer using the client-side ASPxClientReportDesigner.CustomizeToolbox event as demonstrated below.

    <script type="text/javascript" id="script">
        function customizeToolbox(s, e) {
            var info = e.ControlsFactory.getControlInfo("XRZipCode");
            info.isToolboxItem = true;
        }
    </script>
    
    <dx:ASPxReportDesigner ID="ASPxReportDesigner1" runat="server">      
        <ClientSideEvents CustomizeToolbox="customizeToolbox"/>  
    </dx:ASPxReportDesigner>
    
See Also