Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
595
Display the exception message instead of general message while editing the grid
posted

Hi,

How to display the exception message from the property setter  in the message box instead of the default message "unable to set cell value"?

For example

public uint Range
    {
      get
      {
        return this.range;
      }
      set
      {
        if ((int) this.range == (int) value)
          return;
        this.Validate(value);
        this.range = value;
        this.OnNotifyPropertyChanged("Range");
      }
    }

    private void Validate(uint value)

    {

                if(value!=5)

                {

                    throw new InvalidOperationException("The value is not correct");

                }

        }

  • 34810
    Verified Answer
    Offline posted

    Hello Ramesh,

    Thank you for your post.

    I'm not sure that you will be able to do this through a property setter for your XamDataGrid, but there exists an event on the XamDataGrid that may help you on this matter. The name of this event is DataError, and it fires whenever a validation error occurs, such as the "Unable to set cell value" message box that you are currently seeing.

    By handling this event, you can utilize the various properties on the event arguments of that event's handler to modify the message that is shown in the message box. To directly do this, you can modify the e.Message property of the event arguments. These event arguments can also net you the exception that is being thrown as a result of the validation, the cell that this exception is being thrown on, and the operation that caused this exception(such as cell value get/set), among others.

    I have attached a sample project that demonstrates the usage of this DataError event to change the message box text. Simply enter edit mode on one of the cells in the sample, delete all of the text, and then try to exit edit mode to see the result.

    Please let me know if you have any other questions or concerns on this matter.

    Sincerely,
    Andrew
    Associate Developer
    Infragistics Inc.
    www.infragistics.com/support

    TestForLinkLable.zip