Welcome to the Xceed Community Sign in | Join | Help
Community Search  

Customising validation error messages

Sort Posts: Previous Next
  •  05-27-2008, 9:10 PM Post no. 12535

    Customising validation error messages

    I am binding a datagrid to a BindingList of TransectPoint objects (it doesn't matter what a TransectPoint is for this question).

    One of the properties of a TransectPoint is AverageSenescentCrownRadiusProperty (code is below). Note in particular that the value of the property must be > 0 (or null) - as enforced by DoubleIsPositive.

    When editing data in the grid, it will work (almost) perfectly - if I enter a negative value (eg -5) in the column related to this property then the background of the cell will go red. If I hover over the cell it shows this tooltip:

     '-5' is not a valid value for property 'AverageSenescentCrownRadiusProperty'.

    Is there a way to customise the message that is displayed (since I would rather the user not see 'AverageSenescentCrownRadiusProperty')?

    CODE IS BELOW

    public static readonly DependencyProperty AverageSenescentCrownRadiusProperty = DependencyProperty.Register("AverageSenescentCrownRadius", typeof(double?), typeof(TransectPoint), new PropertyMetadata(new double?(0f)), new ValidateValueCallback(DoubleIsPositive));

    [XmlElement("AverageSenescentCrownRadius")]

    public double? AverageSenescentCrownRadius

    {

    get { return (double?)GetValue(AverageSenescentCrownRadiusProperty); }

    set { SetValue(AverageSenescentCrownRadiusProperty, value); }

    }

    private static bool DoubleIsPositive(object value)

    {

    double? tempDouble = (double?) value;

    if (tempDouble.HasValue)

    return tempDouble >= 0;

    else

    return true;

    }

  •  05-28-2008, 8:20 AM Post no. 12541 in reply to 12535

    Re: Customising validation error messages

    You could use ValidationRules as described in the Validating Data topic. The upcoming version of the grid will provide enhanced validation features, including support for IDataErrorInfo.
    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
    Filed under: ,
  •  05-28-2008, 7:06 PM Post no. 12552 in reply to 12541

    Re: Customising validation error messages

    Thanks for the heads up - I will check that article out.

     

    BTW, I think there is a typo in that document:

     (i.e., a row exists edit mode).

    should be:

     (i.e., a row exits edit mode).

  •  05-28-2008, 8:14 PM Post no. 12553 in reply to 12535

    Re: Customising validation error messages

    I solved the issue as follows. Note that it didn't require me to use a CellValidationRule (so I can keep my validation in the object model where I would rather it be than in the UI).

    Note in particular the way I am setting the ToolTip...

     

    <Style x:Key="cell_error" TargetType="{x:Type xcdg:DataCell}">

    <Setter Property="Foreground" Value="Red"/>

    <Setter Property="ToolTip" Value="Invalid value"/>

    </Style>

     

    <xcdg:Column FieldName="AverageSenescentCrownRadius"

    Title="r (Senescent)"

    CellErrorStyle="{StaticResource cell_error}"

    Width="72">

    </xcdg:Column>

     

     

View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.