2

这是一个示例代码:

ButtonEdit be = new ButtonEdit()
{
    DisplayFormatString = MyDisplayFrm,
    MaskType = MaskType.RegEx,
    Mask = "[-+]?([0-9]*[,.])?[0-9]+([eE][-+]?[0-9]+)?",
    ValidateOnTextInput = false
};
Binding bindingValue = new Binding() { Source = PropItem, Path = new PropertyPath("Value"), Mode = BindingMode.TwoWay };
BindingOperations.SetBinding(be, ButtonEdit.EditValueProperty, bindingValue);
be.SetValue(Grid.ColumnProperty, 0);
be.Validate += be_Validate;

void be_Validate(object sender, ValidationEventArgs e)
{
    if ((Convert.ToDouble(e.Value) <= MaxVal) && (Convert.ToDouble(e.Value) >= MinVal)) return;
    MessageBoxResult mbr = MessageBox.Show("The value in not in the suggested range, do you want to continue?", "Min/Max Range validation", MessageBoxButton.YesNo);
    if (mbr == MessageBoxResult.Yes)
    {
        return;
    }
    else
    {
        e.IsValid = false;
        e.ErrorType = DevExpress.XtraEditors.DXErrorProvider.ErrorType.Warning;
        e.ErrorContent = "Value is not in the suggested range. Please correct.";
    }
}

当我将值更改为超出范围并更改焦点时,我会收到两次消息框;一个用于更改值,一个用于更改显示,因为编辑器将值(双倍)显示为适当的科学显示。

如何使 TextEdit(或在上面的 ButtonEdit 示例中)在更改显示时不检查验证?我的意思是它不应该放在首位,不是吗?由于 EditValue 属性没有改变,而只是显示(Text 属性)。

提前致谢 :)

4

1 回答 1

0

请查看此帮助文章 BaseEdit.InvalidValue 事件

AFAIK 您需要处理 Validating 事件并在该事件中设置 e.Cancel 如果值不正确,则为 true,然后在 InvalidValue 事件中,您可以为无效条目提供视觉提示。

希望这可以帮助

于 2011-08-09T02:21:41.310 回答