Ticket Q361616
Visible to All Users

Validation - How to change the default error icons for failed validation rules

created 13 years ago

Hi,

How can I change the Validation Error Icon to a custom icon? WinForms and Asp.Net plataforms.

I tried the code below without success.

<code C#>
        public IntelligixWindowsFormsApplication()
        {
            InitializeComponent();

DXErrorProvider.GetErrorIcon += new GetErrorIconEventHandler(DXErrorProvider_GetErrorIcon);
        }

void DXErrorProvider_GetErrorIcon(GetErrorIconEventArgs e)
        {
            if (e.ErrorType == ErrorType.Critical)
            {
                e.ErrorIcon = ImageLoader.Instance.GetImageInfo("INT_ErrorIcon").Image;

}
        }
</code>

May you give some example?

Thanks.
Sandro.

Comments (1)
Dennis Garavsky (DevExpress) 13 years ago

    Hi Sandro,
    Thank you for the question. Currently, there is no easy way to change this error image. We apologize for all the inconvenience.
    I have converted your ticket to a Bug Report. We will do our best to fix this bug as soon as we can. Your patience is highly appreciated.
    Thanks,
    Sergey

    Answers

    created 13 years ago (modified 9 years ago)

    In the latest XAF v15.2+,  there is a universal and platform-agnostic way to replace the default validation images globally in the application by handling the static DevExpress.ExpressApp.Utils > ImageLoader >CustomGetImageInfo  event.
    Consider the following example code that can be added in YourSolutionName.Module/Module.cs file:

    C#
    using DevExpress.ExpressApp.Utils; namespace MainDemo.Module { public sealed partial class MainDemoModule : ModuleBase { private const string STR_CustomErrorImageName = "BO_Skull"; public MainDemoModule() { InitializeComponent(); /* Dennis: The images corresponding to validation errors may have the followng names by default: "Error" or "State_Validation_Invalid" + size suffix "Warning" or "State_Validation_Warning" + size suffix "Information" or "State_Validation_Information" + size suffix */ ImageLoader.CustomGetImageInfo += (s, e) => { bool isLargeImage = e.ImageName.EndsWith("_32x32") || e.ImageName.EndsWith("_48x48"); if(e.ImageName.Contains("State_Validation_Invalid") || e.ImageName == "Error") { e.Handled = true; e.ImageInfo = isLargeImage ? ImageLoader.Instance.GetLargeImageInfo(STR_CustomErrorImageName) : ImageLoader.Instance.GetImageInfo(STR_CustomErrorImageName); } }; }

    Even thought there is a built-in image used in the example, you can usually replace it with any other image. Refer to the event's documentation for a more complex use-case scenario where the image is obtained from the database.

    And here is the code execution result in an ASP.NET app (the same code will also work in WinForms!):

    Alternatively, you can completely replace the default image using a static approach described in the "Image Source Customizations | Replace Individual Images" section of the Add and Override Images help topic.

    For older versions:
    WinForms:
    You can use the following WindowController:

    C#
    public class ChangeErrorIconController : WindowController { void DXErrorProvider_GetErrorIcon(GetErrorIconEventArgs e) { if(e.ErrorType == ErrorType.Critical) { e.ErrorIcon = DevExpress.ExpressApp.Utils.ImageLoader.Instance.GetImageInfo("BO_Person").Image; } } public ChangeErrorIconController() { DXErrorProvider.GetErrorIcon += new GetErrorIconEventHandler(DXErrorProvider_GetErrorIcon); DevExpress.XtraEditors.BaseEdit.DefaultErrorIcon = DevExpress.ExpressApp.Utils.ImageLoader.Instance.GetImageInfo("BO_Person").Image; } protected override void Dispose(bool disposing) { base.Dispose(disposing); DXErrorProvider.GetErrorIcon -= new GetErrorIconEventHandler(DXErrorProvider_GetErrorIcon); } }

    ASP.NET:
    You can override the standard Error image as described in the http://documentation.devexpress.com/#Xaf/CustomDocument2792 help article. Briefly, you should add the Images folder into your web module project and then copy your own Error image into it.

    Let me know if you experience any difficulties.
    Thanks,
    Dennis

      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.