Home Forums WPF controls Xceed DataGrid for WPF Validation rules bug?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #24554 |

    hello,
    I have a custom validator, for the validation of entier numbres in the datagrid cells:

    public class IntCellValidationRule : CellValidationRule
    {
    public override ValidationResult Validate(object value, CultureInfo cultureInfo, CellValidationContext cellValidationContext)
    {
    if (value == null)
    {
    return new ValidationResult(true, null);
    }

    if (value.ToString() == string.Empty)
    {
    return new ValidationResult(true, null);
    }

    try
    {
    Convert.ToInt32(value);
    }
    catch
    {
    return new ValidationResult(false, “Value must be a integer one.”);
    }

    return new ValidationResult(true, null);
    }

    Well, this validator works wery well: if I type non-integer values in the datagrid, this makes the cell red & invalidate it.

    Now, I would pass the EMPTY values as VALID cells.
    Now, If I pass in the cell without any changes, a empty cell will not be invalidated.
    But If I change the value of a cell to a invalid one (for exemple “zzz”), and then I delete it back to a empty value, this invalidates my cell,
    and the message is not mine – “Value must be a integer one.”
    but a default one – “Imput string was not in a correct format”

    any idea about?

    Imported from legacy forums. Posted by serhio (had 685 views)

    Xceed Support
    Member
    Post count: 5658

    By default, we detect exceptions that occur when we apply the “edited” data to the data item. Whenever an exception occurs when saving the edited value to the data item, we catch that exception and flag the cell as having an “error”.

    In your case, it is most likely that it’s not your IntCellValidationRule that sets the cell as invalid but the exception that occurs when applying the string.Empty value to the Int32 data item after the validation rule has executed.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 301 views)

    User (Old forums)
    Member
    Post count: 23064

    Understood. And what can I do now, for a correct behavior?

    Imported from legacy forums. Posted by serhio (had 348 views)

    User (Old forums)
    Member
    Post count: 23064

    public class MyCustomDataRow : DataRow
    {
    public override void EndEdit()
    {
    if (Text != “”)
    {
    base.EndEdit();
    }
    else
    {
    this.CancelEdit();
    }
    }

    but this is not very symphatic…

    Imported from legacy forums. Posted by serhio (had 3680 views)

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.